我想將我的標頭<h1>
放在名爲light
的div類中,其中包含名爲light.png
的背景圖像。我已經使用Z-index
堆疊了它們,並添加了position:relative
,但仍然沒有將<h1>
放置在<div class=light>
之上。簡單Z索引不起作用
我在做什麼錯?這裏是我的的html代碼:
<body>
<div class="light"></div>
<h1>sdfdsf</h1>
</body>
CSS代碼:
body {
background-image: url(images/bg.jpg);
background-repeat: repeat;
z-index:1;
}
.light {
background-image: url(images/light.png);
margin-left:auto;
margin-right:auto;
z-index:2;
width:763px;
height:566px;
position:relative;
}
h1 {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 48px;
color: rgba(255,255,255,1);
position:relative;
z-index:5;
}
我可以問,爲什麼你不想把h1內的div。如果圖像用於背景圖像,則h1仍將顯示在圖像的頂部。 – 2012-07-28 16:53:07
所以你真的用z-index堆疊它們嗎? – 2012-07-28 16:53:17
將它們封裝在一個外部div中,相對於外部div的位置和絕對位置絕對的兩個內部元素,完成 – Sammaye 2012-07-28 16:54:16