Ответ 1
У меня нет официального объяснения этого, но я знаю, что это связано с контекстами форматирования блоков (MDN, W3C). Я также уверен, что @BoltClock, у которого есть полное понимание BFC (я иногда подозреваю его в написании спецификации в первую очередь), сможет предоставить точное техническое объяснение, если он когда-нибудь захочет это сделать.
Короче говоря, зная, что источник знает об исправлении (проверен и работает): когда вам нужно установить position:relative
на родителя, также установите position:relative
на детей:
/* ... */
.offset {
position: relative; /* This is the culprit! */
}
.offset > * {
position: relative; /* And this is the fix! */
}
ul {
max-height: 0;
overflow: hidden;
margin: 10px;
padding: 0;
border: 10px solid #bada55;
list-style-type: none;
transition: border-color .4s;
}
ul:hover {
max-height: 100px;
border-color: #de2d26;
}
ul > li {
padding: 10px;
pointer-events: auto;
}
.ignorant {
pointer-events: none;
}
.offset {
position: relative; /* This is the culprit! */
}
.offset > * {
position: relative; /* And this is the fix! */
}
<ul class="ignorant">
<li>I am ignorant of your pointer.
If you see me, something went wrong!</li>
</ul>
<ul>
<li>I am not. Hover me!</li>
</ul>
<ul class="ignorant offset">
<li>I should be ignorant of your pointer.
If you see me, something went wrong!</li>
</ul>