-1
定位元素的行爲爲absolute
似乎已經改變。位置絕對內絕對
我有
<div> // position relative
<ul> // position absolute
ul:before // position absolute
<li> // background color on hover
</ul>
</div>
和靜止時,before
僞元件,僅限於ul
。而且無論如何都不可見。即使position
改爲fixed
這似乎輸出
div {
border: 4px solid #525454;
width: 14em;
\t height: 1em;
\t position: relative;
}
div ul {
\t background-color:#fff;
position:absolute;
top:110%;
max-height: 10.68571429rem;
overflow-x: hidden;
overflow-y: auto;
width: calc(100% + 2px);
margin: 0;
padding: 0;
background: #FFF;
box-shadow: 0 2px 3px 0 rgba(34,36,38,.15);
}
div > ul > li:hover{
background-color:beige;
}
div > ul > li {
cursor: pointer;
display: block;
padding:5px 10px;
}
div ul::before {
content: "";
position: absolute;
width: 50px;
height: 102px;
background: linear-gradient(black, yellow, red);
top: -21px;
left: 5px;
z-index:1;
}
<div>
<ul>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
</div>