我有这个样本:
代码HTML:
<div class="select-style">
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
CODE CSS:
.select-style {
padding: 0;
margin: 0;
border: 1px solid #ccc;
width: 120px;
border-radius: 3px;
overflow: hidden;
background-color: #fff;
background: #fff url("http://www.scottgood.com/jsg/blog.nsf/images/arrowdown.gif") no-repeat 90% 50%;
}
.select-style select {
padding: 5px 8px;
width: 130%;
border: none;
box-shadow: none;
background-color: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.select-style select:focus {
outline: none;
}
我画了一张照片,以便更好地了解我想要做的事情。
我如何在我的结构上做到这一点?
目前的结构?或者有另一个结构创建HTML?
提前致谢!
答案 0 :(得分:6)
您可以使用linear-gradient
与background-image
结合使用。
background-image
属性允许url()
和linear-gradient()
的组合,因此您可以尝试分离值。与background-position
相同,因为我们使用95px值控制url图像位置,而线性渐变不受中心中心的影响。70% gray
到71% gray
。
.select-style {
background-image: url("http://www.scottgood.com/jsg/blog.nsf/images/arrowdown.gif"), linear-gradient(to right, white 70%, gray 70%, gray 71%, lightgray 71%, lightgray 100%);
background-position: 95px center, center center;
background-repeat: no-repeat;
border: 1px solid #ccc;
border-radius: 3px;
margin: 0;
overflow: hidden;
padding: 0;
width: 120px;
}
.select-style select {
padding: 5px 8px;
width: 130%;
border: none;
box-shadow: none;
background-color: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.select-style select:focus {
outline: none;
}
&#13;
<div class="select-style">
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
&#13;
答案 1 :(得分:4)
您可以使用:pseudo-element来执行此操作。
将:false元素附加到div
并应用所需的background-color
和border-left
属性。要使其可见,请将background-color: transparent
应用于.select-style
。
.select-style {
position: relative;
padding: 0;
margin: 0;
border: 1px solid #ccc;
width: 120px;
border-radius: 3px;
overflow: hidden;
background: transparent url("http://www.scottgood.com/jsg/blog.nsf/images/arrowdown.gif") no-repeat 90% 50%;
}
.select-style select {
padding: 5px 8px;
width: 130%;
border: none;
background-color: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.select-style select:focus {
outline: none;
}
.select-style:after {
position: absolute;
content: '';
width: 36px;
height: 100%;
background-color: #ddd;
border-left: 1px solid #ccc;
top: 0;
right: -1px;
z-index: -1;
border-radius: 0 1px 1px 0;
}
<div class="select-style">
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
答案 2 :(得分:3)
你想要这样的东西吗?
http://codepen.io/anon/pen/bVWmgP
.select-style:after {
content: '';
background-color: #000;
position: absolute;
border-left: 3px solid #F00;
z-index: 0;
top: 0;
right: 0;
bottom: 0;
left: 85px;
}
.select-style:before {
content: '';
background-color: white;
position: absolute;
z-index: -20;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
注意:如果不添加代表该箭头的额外图像,您将无法更改选择列表箭头颜色。