css3制作的下拉菜单
平时我们在做下拉框时,一般是在浏览器自带的下拉框样式上做调整。但有时,自带的下拉框无法满足我们对页面设计美观的要求。今天要再来分享一款基于纯CSS3的自定义下拉select表单。
html代码如下:
css代码如下:
-
.select {
-
display: inline-block;
-
position: relative;
-
vertical-align: middle;
-
overflow: hidden;
-
background: #fff;
-
border: 1px solid #aaa;
-
text-shadow: none;
-
-moz-border-radius: 4px;
-
-webkit-border-radius: 4px;
-
border-radius: 4px;
-
-moz-transition: box-shadow 0.25s ease;
-
-o-transition: box-shadow 0.25s ease;
-
-webkit-transition: box-shadow 0.25s ease;
-
transition: box-shadow 0.25s ease;
-
}
-
-
.select:hover
-
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
-
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
-
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
-
}
-
-
.select:before {
-
position: absolute;
-
top: 0.3em;
-
right: 0.5em;
-
pointer-events: none;
-
}
-
-
.select select {
-
cursor: pointer;
-
padding: 0.5em;
-
padding-right: 2em;
-
width: 130%;
-
border: none;
-
background: transparent;
-
background-image: none;
-
-webkit-appearance: none;
-
-moz-appearance: none;
-
appearance: none;
-
text-indent: 0.01px;
-
color: #666;
-
font-family: "微软雅黑";
-
}
-
-
.select select:focus {
-
outline: none;
-
}
-
-
select:before {
-
font-family: "icons";
-
font-style: normal;
-
font-weight: normal;
-
font-variant: normal;
-
}
-
-
.icon--down:before, .select:before {
-
content: "e600";
-
}
-
-
@font-face {
-
font-family: 'icons';
-
src: url(data:application/font-woff;charset=utf-8;base64,d09GRk9UVE8AAARgAAoAAAAABBgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABDRkYgAAAA9AAAANgAAADYZbVvCE9TLzIAAAHMAAAAYAAAAGAIIvy2Y21hcAAAAiwAAABMAAAATBpVzFdnYXNwAAACeAAAAAgAAAAIAAAAEGhlYWQAAAKAAAAANgAAADYAl8viaGhlYQAAArgAAA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aWNvbW9vbgBpAGMAbwBtAG8AbwBuAFIAZQBnAHUAbABhAHIAaQBjAG8AbQBvAG8AbgBGAG8AbgB0ACAAZwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABJAGMAbwBNAG8AbwBuAC4AAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format("woff");
-
font-weight: normal;
-
font-style: normal;
-
}
其中下拉小箭头是用的@font-face 实现的。@font-face 能够加载服务器端的字体文件,让客户端显示客户端所没有安装的字体。在@font-face网络字体技术之前,浏览器显示网页上文字使用的字体只能限制在电脑里已经安装的几款字体里。而且每个人的电脑里安装的字体是因人而异的。@font-face的作用是从网上下载并使用自定义字体,使页面显示字体不依赖用户的操作系统字体环境。
用户登录
还没有账号?
立即注册