只用CSS美化选择框的实现代码
网站建设 2023-01-28 20:49www.1681989.com免费网站
狼蚁网站SEO优化是一个默认样式的下拉框的长相
Here is the first option The second option
HTML code
<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
一个选择框的某些部分我们是可以美化的,比如字体、边框、颜色、内边距和背景颜色
Here is the first option The second option
烦人的下拉箭头还是保持不变。没有直接美化它的方式,但解决方案还是非常简单的,我们需要用一个div容器包裹在select元素外围
<div class="styled-select">
<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
</div>
下一步我们需要加入一些css,以确保选择框元素被以某种方式美化
.styled-select select {
background: transparent;
width: 268px;
paddg: 5px;
font-size: 16px;
border: 1px solid #c;
height: 34px;
-webkit-appearance: none; /for chrome/
}
我们需要确保选择框的跨度比外围的div容器更宽,这样默认的下拉箭头就会消失(译者注选择框比外面的div宽大,默认的下拉箭头就会被隐藏)
狼蚁网站SEO优化是我们要用的新下拉箭头
我们的div容器需要被美化成新的下拉箭头出现在我们预想的位置
.styled-select {
width: 240px;
height: 34px;
overflow: hidden;
background: url(new_arrow.png) no-repeat right #ddd;
}
知道这点解决办法将使你非常容易的,不用别的只使用css就能美化您的选择框。
译者注在线调式地址 ,各位看官可自行进入调试
Here is the first option The second option
HTML code
复制代码
代码如下:<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
一个选择框的某些部分我们是可以美化的,比如字体、边框、颜色、内边距和背景颜色
Here is the first option The second option
烦人的下拉箭头还是保持不变。没有直接美化它的方式,但解决方案还是非常简单的,我们需要用一个div容器包裹在select元素外围
复制代码
代码如下:<div class="styled-select">
<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
</div>
下一步我们需要加入一些css,以确保选择框元素被以某种方式美化
复制代码
代码如下:.styled-select select {
background: transparent;
width: 268px;
paddg: 5px;
font-size: 16px;
border: 1px solid #c;
height: 34px;
-webkit-appearance: none; /for chrome/
}
我们需要确保选择框的跨度比外围的div容器更宽,这样默认的下拉箭头就会消失(译者注选择框比外面的div宽大,默认的下拉箭头就会被隐藏)
狼蚁网站SEO优化是我们要用的新下拉箭头
我们的div容器需要被美化成新的下拉箭头出现在我们预想的位置
复制代码
代码如下:.styled-select {
width: 240px;
height: 34px;
overflow: hidden;
background: url(new_arrow.png) no-repeat right #ddd;
}
知道这点解决办法将使你非常容易的,不用别的只使用css就能美化您的选择框。
译者注在线调式地址 ,各位看官可自行进入调试