Css 将上一个(第一个已定义的)div置于下一个(第二个)div的前面,并使用默认位置
我有2个Css 将上一个(第一个已定义的)div置于下一个(第二个)div的前面,并使用默认位置,css,html,z-index,Css,Html,Z Index,我有2个divs,并希望第一个定义的div(称为befront)位于紧接其后定义的div前面(称为beback) 使用位置:绝对破坏了设计,所以我只想使用不起作用的z-index 我使用了以下CSS,但运气不佳: #befront { width:100%; height:20px; background:red; /* I expect that the rex box be in front of the yellow box*/ margin-bottom:-20p
div
s,并希望第一个定义的div
(称为befront
)位于紧接其后定义的div
前面(称为beback
)
使用位置:绝对
破坏了设计,所以我只想使用不起作用的z-index
我使用了以下CSS,但运气不佳:
#befront {
width:100%; height:20px; background:red;
/* I expect that the rex box be in front of the yellow box*/
margin-bottom:-20px;
z-index: 1000;
}
#beback {
width:100%; height:20px; background:yellow;z-index:1;
}
你能不能在你的“#befront”后面加上“position:relative”
z索引要求元素的位置正确,才能正常工作
请参见尝试将
#beback
的z-index
设为负值。将其更改为-1或更低。
并添加位置
,其值为绝对值
或相对值
#befront {
width:100%; height:20px; background:red;
/* I expect that the rex box be in front of the yellow box*/
margin-bottom:-20px;
z-index: 1000;
position: relative;
}
#beback {
width:100%; height:20px; background:yellow;z-index:1;
}