简体   繁体   English

HTML选择下拉箭头样式

[英]HTML select dropdown arrow style

How to get the select dropdown arrow styled like shown in the image below. 如何获得样式如下图所示的选择下拉箭头。

<select>
    <option>Select Any</option>
    <option>Option 1</option>
    <option>Option 2</option>
</select>

在此处输入图片说明

Try this: 尝试这个:

HTML: HTML:

<div class="styled-select slate">
  <select>
    <option>Here is the first option</option>
    <option>The second option</option>
    <option>The third option</option>
  </select>
</div>

CSS: CSS:

div { margin: 20px; }

.styled-select {
   height: 29px;
   overflow: hidden;
   width: 240px;
}

.styled-select select {
   background: transparent;
   border: none;
   font-size: 14px;
   height: 29px;
   padding: 5px; /* If you add too much padding here, the options won't show in IE */
   width: 268px;
}

.styled-select.slate {
   background: url(http://i.stack.imgur.com/8CVVr.png) no-repeat right center;
   height: 34px;
   width: 240px;
}

How about this... Just set that image to Select's background. 怎么样...只需将该图像设置为Select的背景即可。

 .select-style { width: 268px; line-height: 1; border: 0; overflow: hidden; height: 34px; position:relative; background:#fff; } .select-style>select{ -webkit-appearance: none; appearance:none; -moz-appearance:none; width:100%; background:none; background:transparent; border:none; outline:none; cursor:pointer; padding:7px 10px; } .select-style>span{ position:absolute; bottom: 0; right: 0; height: 0; width: 0; cursor:pointer; border-right: 10px solid #ff0099; border-bottom: 10px solid #ff0099; border-left: 10px solid transparent; border-top: 10px solid transparent; } select::-ms-expand { display: none; } 
 <div class="select-style"> <select> <option>Select Any</option> <option>Option 1</option> <option>Option 2</option> </select> <span></span> </div> 

Fiddle: https://jsfiddle.net/sank8893/bhy9do60/9/ 小提琴: https : //jsfiddle.net/sank8893/bhy9do60/9/

see here jsfiddle 看到这里jsfiddle

first you need to remove the default styling of the select dropdown. 首先,您需要删除select下拉列表的默认样式。 to do that use 这样做

-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

for IE use : 对于IE使用:

select::-ms-expand { 
display: none;
}    

then just apply your desired style, in this case with background-image 然后只应用您想要的样式,在这种情况下使用background-image

or you can use border to make a triangle and place it by using pseudo-elements like :before or :after . 或者,您可以使用border制作一个三角形,然后使用伪元素(如:before:after放置它。

select { 
    background:url("http://i.stack.imgur.com/8CVVr.png") no-repeat scroll right  bottom;
    background-size:contain;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding:5px 10px;
}

As others have mentioned you can hide the default select arrow by appearance property and apply your own style. 正如其他人提到的那样,您可以按外观属性隐藏默认的选择箭头并应用您自己的样式。

To support lower versions of IE(i haven't consider below 9) as appearance property won't work even with ms prefix , you can use the below method to have common support. 要支持较低版本的IE(我没有考虑低于9),因为外观属性即使使用ms前缀也无法使用,您可以使用以下方法获得通用支持。

Arrow made by css not an image. css制成的箭头不是图像。

 $( "#sel_val" ).change(function() { var option = $(this).find('option:selected').val(); $('#sel_txt').text(option); }); 
 .wrapper{width:250px;margin:10px auto;} .sbx{ margin:0; width:100%; font-family:arial; position:relative; background-color:#eee; } .cus_selt:after{content:'';width:0; height:0; border-left:10px solid transparent; border-right:10px solid transparent; border-top:10px solid #FD025F; position:absolute; bottom:-1px; z-index:2; right:-6px; transform:rotate(-45deg); } .cus_selt{padding:20px;display:block;} .styled { float:left; height: 56px; margin: -58px 0 0; opacity: 0; width: 100%; filter: alpha(opacity=0); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="wrapper"> <div class="sbx" id="yoe_fld"> <span class="cus_selt" id="sel_txt">Select a value*</span> <select id="sel_val" class="styled"> <option>Select</option> <option>option1</option> <option>option2</option> <option>option3</option> <option>option4</option> <option>option5</option> <option>option6</option> <option>option7</option> </select> </div> </div> 

Source link for custom select dropdown click 源链接,自定义选择下拉菜单中点击

Source link for CSS arrow click CSS箭头的源链接, 请单击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM