首页 > 代码库 > css实现下拉框
css实现下拉框
CSS:
a, label {
display: block;
border-bottom: 1px solid #ccc;
padding: 1em 2em;
width: 100%;
color: #000;
text-decoration: none;
cursor: pointer;
}
.all-items {
display: none;
}
.show-all {
display: none;
}
.list {
position: relative;
padding-bottom: 3.188em;
}
label {
position: absolute;
bottom: 0;
}
label:before {
content: "More";
}
.show-all:checked ~ .all-items {
display: block;
}
.show-all:checked + label:before {
content: "Less";
}
HTML:
<div class="list">
<a href="http://www.mamicode.com/#">Micket</a>
<a href="http://www.mamicode.com/#">Mace Windu</a>
<a href="http://www.mamicode.com/#">Count Dooku</a>
<a href="http://www.mamicode.com/#">Admiral Ackbar</a>
<a href="http://www.mamicode.com/#">Padme Amidala</a>
<input id="show-all" class="show-all" type="checkbox" />
<label for="show-all"></label>
<div class="all-items">
<a href="http://www.mamicode.com/#">Gamorrean Guards</a>
<a href="http://www.mamicode.com/#">C-3P0</a>
<a href="http://www.mamicode.com/#">Qui-Gin Jinn</a>
<a href="http://www.mamicode.com/#">Imperial Guards</a>
<a href="http://www.mamicode.com/#">Obi-Wan Kenobi</a>
<a href="http://www.mamicode.com/#">Tie Fighter Pilot</a>
<a href="http://www.mamicode.com/#">Greedo</a>
</div>
</div>
不兼容IE6、7、8
转自:http://modernweb.com/2014/07/30/5-things-wont-believe-built-css/