我创建了一个只有纯css的下拉列表,但问题是它正在向下推送其他内容。有人可以帮忙吗?
HTML:
<div class="select">
<input id="is-focus" type="radio" name="item" />
<label for="is-focus"><span class="label"></span></label>
<ul class="options">
<li>
<input type="radio" name="item" value="pie" id="pie" />
<label for="pie" data-title="Pie">Pie</label>
</li>
<li>
<input type="radio" name="item" value="cake" id="cake" />
<label for="cake" data-title="Cake">Cake</label>
</li>
</ul>
</div>
CSS:
.select {
position: relative;
overflow: hidden;
}
.select .label {
padding: 8px;
max-width: 150px;
}
.select .label:after {
content: "";
position: absolute;
left: 12px;
top: 14px;
border: 8px solid transparent;
border-top-color: #999;
}
.select label {
max-width: 150px;
display: block;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 3px;
padding: 8px;
cursor: pointer;
}
.select .options {
max-width: 220px;
margin: 0;
padding: 0;
color: #666;
height: 0;
border-right: 1px dotted #999;
border-left: 1px dotted #999;
border-radius: 5px;
max-height: 162px;
overflow-y: auto;
overflow-x: hidden;
}
.select .options:hover {
height: auto;
border-bottom: 2px solid #999;
}
.select .options li label {
text-align: left;
display: block;
padding: 6px 220px 6px 15px;
cursor: pointer;
overflow: hidden;
box-sizing: border-box;
}
.select .options li label:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0));
}
.select .options li [type="radio"] {
position: absolute;
display: block;
left: -999px;
}
.select .options li [type="radio"]:checked ~ label:after {
content: attr(data-title);
display: block;
position: absolute;
top: 6px;
left: 20px;
padding: 5px 25px;
color: #666;
pointer-events: none;
font-size: 80%;
overflow: hidden;
}
.select #is-focus {
position: absolute;
display: block;
opacity: 0;
left: 150px;
}
.select #is-focus:focus ~ label span.label:after {
border-top-color: transparent;
border-bottom-color: #999;
top: 0.3em;
}
.select #is-focus:focus ~ .options {
height: auto;
border-bottom: 2px solid #999;
}
这是我尝试做的代码链接: http://codepen.io/anon/pen/ogYKzQ
谢谢
答案 0 :(得分:0)
将.options位置从静态更改为固定 并在菜单标签上添加白色背景。
答案 1 :(得分:0)
想出来。将.select的位置设置为绝对值,将label的背景设置为白色,并为其添加z-index。