純css實現下拉菜單
一、效果以下:
二、html代碼
<div class="drop-box">
<p class="txt">時間最近</p>
<ul class="menu">
<li sort="0" style="display: none;">時間最近</li>
<li sort="1">評論最多</li>
<li sort="2">被贊最多</li>
</ul>
</div>
三、css代碼
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.drop-box {
box-sizing: border-box;
width: 150px;
font-size: 14px;
text-align: center;
border-radius: 10px;
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.175);
overflow: hidden;
margin-bottom: 5px;
}
.drop-box p {
height: 24px;
padding-top: 5px;
position: relative;
z-index: 10;
margin: 0px;
}
.drop-box p:after { /*三角箭頭*/
position: absolute;
top: 10px;
right: 10px;
width: 0px;
height: 0px;
content: '';
border: 6px solid transparent;
border-top-color: #E4E4E3;
}
.drop-box .menu {
display: none;
background-color: #fff;
}
.drop-box .menu li {
height: 35px;
line-height: 35px;
}
.drop-box .menu li:hover {
background-color: #fee5ca;
color: #fda653;
}
.drop-box .menu .dp-active {
display: none;
}
.drop-box:hover {
cursor: pointer;
}
.drop-box:hover .menu {
display: block;
}
.drop-box:hover p:after {
top: 5px;
border: 6px solid transparent;
border-bottom-color: #E4E4E3;
}
</style>