有没有在select2中添加主题标签的理想场所?

时间:2019-06-21 08:10:51

标签: javascript jquery

我想知道在select2中是否有理想的位置添加'theme'标签

我试图将一个类添加到select2下拉列表和容器元素中,然后遇到了主题标签。我尝试在开始时添加它,但这不起作用

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" type="image/x-icon" href="https://static.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />
<link rel="mask-icon" type="" href="https://static.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg" color="#111" />
<title>CodePen - Select2 Material Design theme</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.css'>
<style>
      /**
 * Basic styles
 */
body {
  overflow-x: hidden;
  overflow-y: scroll;
  max-width: 600px;
  margin: 2rem auto;
}

ul {
  margin: 0;
  padding: 0;
}

:focus {
  outline: none;
}

:disabled {
  background-color: transparent;
}

/**
 * Multiple Select2
 */
.select2-container--material {
  width: 100% !important;
  /**
   * Textbox
   */
  /**
   * Dropdown
   */
  /**
   * Options
   */
  /**
   * Focused textbox
   */
  /**
   * Disabled textbox
   */
}
.select2-container--material ::-webkit-input-placeholder {
  color: inherit;
}
.select2-container--material :-ms-input-placeholder {
  color: inherit;
}
.select2-container--material ::-ms-input-placeholder {
  color: inherit;
}
.select2-container--material ::placeholder {
  color: inherit;
}
.select2-container--material .select2-selection {
  /* @extend input */
  overflow: visible;
  font: inherit;
  touch-action: manipulation;
  margin: 0;
  line-height: inherit;
  border-radius: 0;
  box-sizing: inherit;
  /* @extend .form-control */
  display: block;
  width: 100%;
  color: #55595c;
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: .5rem 0 .6rem;
  font-size: 1rem;
  line-height: 1.5;
  background-color: transparent;
  background-image: none;
  border-radius: 0;
  margin-top: .2rem;
  margin-bottom: 1rem;
  /* @extend input[type=text] */
  background-color: transparent;
  border: none;
  border-bottom: 1px solid #ccc;
  border-radius: 0;
  outline: 0;
  width: 100%;
  font-size: 1rem;
  box-shadow: none;
  transition: all .3s;
  min-height: 2.1rem;
}
.select2-container--material .select2-selection .select2-selection__rendered {
  padding-left: 0;
}
.select2-container--material .select2-selection--single .select2-selection__rendered {
  float: left;
}
.select2-container--material .select2-selection--single .select2-selection__arrow {
  float: right;
}
.select2-container--material .select2-selection--multiple {
  /**
   * Multiple selected options
   */
  /**
   * Multiple selected option clear button
   */
}
.select2-container--material .select2-selection--multiple .select2-selection__rendered {
  width: 100%;
}
.select2-container--material .select2-selection--multiple .select2-selection__rendered li {
  list-style: none;
}
.select2-container--material .select2-selection--multiple .select2-selection__choice {
  /* @extend .mdl-chip */
  height: 32px;
  line-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 16px;
  background-color: #dedede;
  display: inline-block;
  color: rgba(0, 0, 0, 0.87);
  margin: 2px 0;
  font-size: 0;
  white-space: nowrap;
  /* @extend .mdl-chip__text */
  font-size: 13px;
  vertical-align: middle;
  display: inline-block;
  float: left;
  margin-right: 8px;
  margin-bottom: 4px;
}
.select2-container--material .select2-selection--multiple .select2-selection__choice__remove {
  /* Hide default content */
  font-size: 0;
  opacity: 0.38;
  cursor: pointer;
  float: right;
  margin-top: 4px;
  margin-right: -6px;
  margin-left: 6px;
  transition: opacity;
}
.select2-container--material .select2-selection--multiple .select2-selection__choice__remove::before {
  content: "cancel";
  /* @extend .material-icons */
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  color: #000;
}
.select2-container--material .select2-selection--multiple .select2-selection__choice__remove:hover {
  opacity: 0.54;
}
.select2-container--material .select2-search--inline .select2-search__field {
  width: 100%;
  margin-top: 0;
  /* Match input[type=text] */
  height: 34px;
  line-height: 1;
}
.select2-container--material .select2-dropdown {
  border: 0;
}
.select2-container--material .select2-dropdown .select2-search__field {
  min-height: 2.1rem;
  margin-bottom: 16px;
  border: 0;
  border-bottom: 1px solid #ccc;
  transition: all .3s;
}
.select2-container--material .select2-dropdown .select2-search__field:focus {
  border-bottom: 1px solid #4285f4;
  box-shadow: 0 1px 0 0 #4585f4;
}
.select2-container--material .select2-results__options {
  /* @extend .zf-shadow-depth* */
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  /* @extend .dropdown-content */
  background-color: #fff;
  margin: 0;
  min-width: 100px;
  max-height: 650px;
  overflow-y: auto;
  z-index: 999;
  will-change: width,height;
  /* @extend .dropdown-content inline styles */
}
.select2-container--material .select2-results__option {
  /* @extend .dropdown-content li */
  cursor: pointer;
  clear: both;
  color: rgba(0, 0, 0, 0.87);
  line-height: 1.5rem;
  text-align: left;
  text-transform: none;
  /* @extend .dropdown-content li>a, .dropdown-content li>span */
  font-size: 1.2rem;
  display: block;
  padding: 1rem;
  /**
   * Disabled options
   */
  /**
   * Selected option
   */
  /**
   * Active/hovered option
   */
}
.select2-container--material .select2-results__option[aria-disabled=true] {
  /* @extend .select-dropdown li.disabled */
  color: rgba(0, 0, 0, 0.3);
  background-color: transparent !important;
  cursor: context-menu;
  /* @extend .disabled */
  cursor: not-allowed;
}
.select2-container--material .select2-results__option[aria-selected=true] {
  /* @extend .dropdown-content li:active, .dropdow-content li:hover */
  color: #4285f4;
  background-color: #eee;
}
.select2-container--material .select2-results__option--highlighted[aria-selected] {
  background-color: #ddd;
}
.select2-container--material.select2-container--focus .select2-selection {
  /* @extend input[type=text]:focus */
  border-bottom: 1px solid #4285f4;
  box-shadow: 0 1px 0 0 #4585f4;
}
.select2-container--material.select2-container--disabled .select2-selection {
  /* @extend .select-wrapper input.select-dropdown:disabled */
  color: rgba(0, 0, 0, 0.3);
  cursor: default;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
.select2-container--material.select2-container--disabled.select2-container--focus .select2-selection {
  box-shadow: none;
}

    </style>
<script>
  window.console = window.console || function(t) {};
</script>
<script>
  if (document.location.search.match(/type=embed/gi)) {
    window.parent.postMessage("resize", "*");
  }
</script>
</head>
<body translate="no">
<select class="js-select2">
<option value="AK" disabled>Alaska</option>
<option value="HI">Hawaii</option>
<option value="CA">California</option>
<option value="NV">Nevada</option>
<option value="OR" disabled>Oregon</option>
<option value="WA">Washington</option>
<option value="AZ">Arizona</option>
<option value="CO">Colorado</option>
<option value="ID">Idaho</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NM">New Mexico</option>
<option value="ND">North Dakota</option>
<option value="UT">Utah</option>
<option value="WY">Wyoming</option>
<option value="AL">Alabama</option>
<option value="AR">Arkansas</option>
<option value="IL">Illinois</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="OK">Oklahoma</option>
<option value="SD">South Dakota</option>
<option value="TX">Texas</option>
<option value="TN">Tennessee</option>
<option value="WI">Wisconsin</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="IN">Indiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="OH">Ohio</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WV">West Virginia</option>
</select>
<select class="js-select2" multiple>
<option value="AK" disabled>Alaska</option>
<option value="HI">Hawaii</option>
<option value="CA">California</option>
<option value="NV">Nevada</option>
<option value="OR" disabled>Oregon</option>
<option value="WA">Washington</option>
<option value="AZ">Arizona</option>
<option value="CO">Colorado</option>
<option value="ID">Idaho</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NM">New Mexico</option>
<option value="ND">North Dakota</option>
<option value="UT">Utah</option>
<option value="WY">Wyoming</option>
<option value="AL">Alabama</option>
<option value="AR">Arkansas</option>
<option value="IL">Illinois</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="OK">Oklahoma</option>
<option value="SD">South Dakota</option>
<option value="TX">Texas</option>
<option value="TN">Tennessee</option>
<option value="WI">Wisconsin</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="IN">Indiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="OH">Ohio</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WV">West Virginia</option>
</select>
<script src="https://static.codepen.io/assets/common/stopExecutionOnTimeout-de7e2ef6bfefd24b79a3f68b414b87b8db5b08439cac3f1012092b2290c719cd.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js'></script>
<script id="rendered-js">
      "use strict";

$(document).ready(function domReady() {
  $(".js-select2").select2({
    placeholder: "Pick states",
    theme: "material" });


  $(".select2-selection__arrow").
  addClass("material-icons").
  html("arrow_drop_down");
});
      //# sourceURL=pen.js
    </script>
</body>
</html>