我试图让无序列表显示为选择框,如果可能的话,不使用Javascript。我不知道从哪里拿这个。
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: inherit;
font-family: inherit;
font-size: inherit;
text-decoration: none;
display: inline-block;
white-space: nowrap;
margin: 0;
padding: 0.2em 0.4em;
width: 100%;
border: 1px solid #acacac;
background: #fff;
}
select {
position: relative;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
select:disabled {
z-index: 1;
}
.select-wrap {
display: inline-block;
width: 100%;
position: relative;
}
.select-wrap:after {
content: '\f078'; /* fa-chevron-down */
font-family: FontAwesome;
position: absolute;
pointer-events: none;
right: 0.5em;
top: 0.2em;
}
option {
padding-left: 0.5em;
}
/* Now for the list */
a {
text-decoration: none;
}
ul.select {
list-style: none;
display: inline-block;
white-space: nowrap;
margin: 0;
padding: 0.2em 0.4em;
width: 100%;
border-width: 1px;
border-style: solid;
border-color: #acacac;
background: #fff;
}
ul.select li a {
display: block;
color: inherit;
width: 100%;
}
<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css?ver=1.0' type='text/css' media='all' />
<div class="select-wrap">
<select id="Select1">
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
</select>
</div>
<!-- /.select-wrap-->
<br />
<br />
<div class="select-wrap">
<ul class="select">
<li><a href="#" title="First">First</a>
</li>
<li><a href="#" title="Second">Second</a>
</li>
<li><a href="#" title="Third">Third</a>
</li>
</ul>
</div>
答案 0 :(得分:3)
<input type="checkbox">
:checked
与<label>
非常接近,可以处理下拉列表。并使用default
进行样式设置。但它不会像<select>
中那样选择.container {
position: relative;
}
.select-checkbox {
display: none;
}
.select-label {
display: block;
border: 1px solid;
padding: 4px;
}
.select-label:before {
content: "\25BE";
float: right;
}
.select-wrap {
position: absolute;
width: 100%;
background: #eee;
display: none;
}
.select-checkbox:checked ~ .select-wrap {
display: block;
}
.select {
list-style: none;
padding: 10px;
margin: 0;
}
.select a {
display: block;
text-decoration: none;
color: inherit;
}
所选项目。
<div class="container">
<input type="checkbox" class="select-checkbox" id="c1">
<label for="c1" class="select-label">Click to open dropdown</label>
<div class="select-wrap">
<ul class="select">
<li><a href="#" title="First">First</a></li>
<li><a href="#" title="Second">Second</a></li>
<li><a href="#" title="Third">Third</a></li>
</ul>
</div>
</div>
...
&#13;
{{1}}&#13;
答案 1 :(得分:1)
我相信这是你想要完成的事情?
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #2980b9;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
color: #fff;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
min-width: 80px;
background-color: #555;
}
ul li ul li > a {
text-decoration: none;
display: block;
color: #fff;
}
ul li ul li:hover {
background: #666;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li > span {
display: inline-block;
margin: 0 0 -3px 5px;
width: 12px;
height: 12px;
background-image: url('https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-24.png');
background-size: 12px 12px;
}
&#13;
<ul>
<li>
First<span class="arrow-down"></span>
<ul>
<li><a href="http://www.stackoverflow.com">Second</a></li>
<li><a href="http://www.stackoverflow.com">Third</a></li>
</ul>
</li>
</ul>
<div class="select-wrap">
&#13;
答案 2 :(得分:1)
最接近我没有js
.select{
height:20px;
width:200px;
overflow:hidden;
background-color:#FFFFFF;
border:1px solid #CCCCCC;
padding:0px;
margin:0px;
cursor:pointer;
}
.select:hover{
height:auto;
}
.select li{
height:20px;
line-height:20px;
padding-left:5px;
}
.select li:hover{
background-color:#EEEEFF;
}
.select li a{
text-decoration:none;
color:#000000;
font-family:calibri;
}
.select li:first-child a:after{
content:' ';
background-image: url('https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-24.png');
background-size:16px 16px;
background-position:center center;
background-repeat:no-repeat;
float:right;
height:20px;
width:20px;
text-align:center;
line-height:20px;
}
&#13;
<ul class="select">
<li><a href="#" title="First">First</a></li>
<li><a href="#" title="Second">Second</a></li>
<li><a href="#" title="Third">Third</a></li>
</ul>
&#13;