bootstrap-selectpicker不改变框宽 [英] bootstrap-selectpicker not changing box width

查看:118
本文介绍了bootstrap-selectpicker不改变框宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改显示所选选项的selectpicker框的宽度,但无论我尝试什么,我都无法更改它,也无法更改框的颜色。

I am trying to change the width of the selectpicker box that shows selected options, but no matter what I try I am unable to change it, nor am I able to change the color of the box.

任何想法或建议都表示赞赏。

Any ideas or suggestions are appreciated.

我所假设的代码片段应更改框宽度如下(尽可能看我把它一直设置为25但宽度仍然很宽):

Code Snippet for what I have assuming should change the box width is as follows (as you can see I set it all the way down to 25 but the width is still quite wide):

.selectpicker {
width: 25px;

您可以运行的代码段:

<script>
  $(function() {
    $('[data-toggle="tooltip"]').tooltip()
  }) 
</script>

<script type = "text/javascript">
  $(window).on('load', function() {
      $('.selectpicker').selectpicker({
      'selectedText': 'cat'
      });
      // $('.selectpicker').selectpicker('hide');  
  }); 
</script>

.text-muted {
  font-size: small;
}

.text-bold {
  font-weight: bold;
  font-size: small;
}

.button {
  background-color: #008CBA;
  /* Light Blue */
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 11px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 4px;
  padding: 6px 10px;
}

.button2 {
  background-color: #008CBA;
  /* Light Blue */
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 11px;
  margin: 8px 2px;
  cursor: pointer;
  border-radius: 4px;
  padding: 6px 10px;
}

.button2:hover {
  background-color: #008CBA;
  box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 30px 0 rgba(0, 0, 0, 0.19);
  padding: 6px 10px;
}


/* Blue */

.button3 {
  background-color: #f44336;
}


/* Red */

.button4 {
  background-color: #e7e7e7;
  color: black;
}


/* Gray */

.button5 {
  background-color: #555555;
}


/* Black */

.button6 {
  font-size: 12px;
  padding: 8px 8px;
  margin: 8px 0;
  box-sizing: border-box;
  border: none;
  background-color: #D35324;
  color: white;
  padding: 6px 10px;
}

.button6:hover {
  background-color: #037BA2;
  color: white;
  box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 30px 0 rgba(0, 0, 0, 0.19);
}

.button7 {
  font-size: 12px;
  padding: 8px 8px;
  margin: 8px 0;
  box-sizing: border-box;
  border: none;
  background-color: #008CBA;
  color: white;
}

.button7:hover {
  background-color: #008CBA;
  color: white;
  box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 30px 0 rgba(0, 0, 0, 0.19);
}

td {
  text-align: left;
  valign="middle";
}

i {
  border: solid white;
  border-width: 0 1px 1px 0;
  display: inline-block;
  padding: 2px;
}

.right {
  transform: rotate(-45deg);
  -webkit-transform: rotate(-45deg);
}

.left {
  transform: rotate(135deg);
  -webkit-transform: rotate(135deg);
}

.up {
  transform: rotate(-135deg);
  -webkit-transform: rotate(-135deg);
}

.down {
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
}

.dropbtn {
  background-color: #008CBA;
  color: white;
  padding: 12px;
  font-size: 12px;
  border: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 120px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.dropdown-content a {
  color: #037BA2;
  padding: 6px 6px;
  text-align: center;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #037BA2;
  color: white;
}

.dropdown:hover .dropdown-content {
  display: block;
  padding-top: 3px;
  right: 0;
}

.dropdown:hover .dropbtn {
  background-color: #037BA2;
}

input[id=Search],
select {
  padding: 8px 20px;
  margin: 8px 0;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}

input[value=Apply] {
  font-size: 12px;
  padding: 8px 8px;
  margin: 8px 0;
  box-sizing: border-box;
  border: none;
  background-color: #D35324;
  color: white;
}

input[value=Reset] {
  font-size: 12px;
  padding: 8px 8px;
  margin: 8px 0;
  box-sizing: border-box;
  border: none;
  background-color: #D35324;
  color: white;
}

input[value=Apply]:hover {
  background-color: #C44E22;
}

input[value=Reset]:hover {
  background-color: #C44E22;
}

table.table1,
th.th1,
td.td1 {
  width: 100%;
  color: white;
  font-size: 16px;
  padding-left: 10px;
  background-color: #008CBA;
}

.tooltip {
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 220px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 150%;
  left: 50%;
  margin-left: -60px;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent black transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}

.glyphicon.glyphicon-info-sign {
  font-size: 25px;
  top: 5px;
}

.selectpicker {
  width: 25px;
  height: 37px;
  background-color: #008CBA !important;
  border-style: solid;
  border-left-width: 3px;
  border-top: none;
  border-bottom: none;
  border-right: none;
  color: black;
  font-size: 14px;
  font-weight: 200;
  padding-left: 6px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

<head>


  <!-- Bootstrap core CSS -->
  <link href="dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script>




  <!-- JQUERY -->
  <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>


  <!--  BOOTSTRAP SELECT -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />




  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <link href="assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="dashboard.css" rel="stylesheet">

  <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
  <!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
  <script src="assets/js/ie-emulation-modes-warning.js"></script>

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->



</head>

<body>
  <h3>START OF TESTING</h3>
  <p><br><br></p>
  <select class="selectpicker" data-style="btn-info" multiple data-max-options="4" data-actions-box="true">

    <optgroup label="Select options below">
      <option>Active</option>
      <option>Inactive</option>
      <option>Leave</option>
      <option>No Status</option>
    </optgroup>
  </select>

  <p><br><br></p>
  <p><br><br></p>
  <p><br><br></p>
  <p><br><br></p>
  <h3>END OF TESTING</h3>
  <p><br><br></p>
  <p><br><br></p>
  <p><br><br></p>
  <p><br><br></p>
  <p><br><br></p>






</body>

推荐答案

在select选项中使用data-content属性。
例如:

Use data-content attribute in select option. For example:

<select class="selectpicker form-control" data-live-search="true" id="subject_teacher_drop_down">
    <option data-content="English">English</option>
    <option data-content="Methodology of social...">Methodology of social science with special reference to economics</option>
</select>

这篇关于bootstrap-selectpicker不改变框宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆