Chcę element (div
) należy warstwowy pod jego stałą rodzica (header
):Element pod jego stałą rodzica przy użyciu `Z-index` w Chrome
header {
position: fixed;
width: 100%;
height: 100px;
background-color: #ccc;
}
header > div {
position: absolute;
height: 100%;
width: 100px;
z-index: -1;
transform: translateY(50%);
background-color: #aaa;
}
<header>
<div>
</div>
</header>
to działa w Firefox, ale nie w Chrome. Aby to naprawić trzeba to zrobić:
header {
position: fixed;
width: 100%;
height: 100px;
}
header > div {
position: relative;
width: 100%;
height: 100%;
background-color: #ccc;
}
header > div > div {
position: absolute;
height: 100%;
width: 100px;
z-index: -1;
transform: translateY(50%);
background-color: #aaa;
}
<header>
<div>
<div>
</div>
</div>
</header>
Ale to jest do bani! Kto jest w błędzie zgodnie ze specyfikacją Firefox lub Chrome? Czy istnieje lepsze podejście, aby to zrobić w różnych przeglądarkach?
możliwe duplikat [chrom: nie można ustawić jeden nad drugim absolutnego div gdy dominująca jest stały] (http://stackoverflow.com/questions/13798669/chrome-cant- position-one-absolute-div-over-another-when-the-parent-is-fixed) – Anonymous