2013-10-26 32 views
-1

我想要調整z索引順序,以便第一個類比第二個類更接近。CSS Z-Index問題

但我不能爲我的生活得到一個盒子陰影來顯示。

.title { 
     background-image: linear-gradient(bottom, rgb(249,252,249) 33%, rgb(255,255,255) 37%); 
     background-image: -o-linear-gradient(bottom, rgb(249,252,249) 33%, rgb(255,255,255) 37%); 
     background-image: -moz-linear-gradient(bottom, rgb(249,252,249) 33%, rgb(255,255,255) 37%); 
     background-image: -webkit-linear-gradient(bottom, rgb(249,252,249) 33%, rgb(255,255,255) 37%); 
     background-image: -ms-linear-gradient(bottom, rgb(249,252,249) 33%, rgb(255,255,255) 37%); 

     background-image: -webkit-gradient(
      linear, 
      left bottom, 
      left top, 
      color-stop(0.33, rgb(249,252,249)), 
      color-stop(0.37, rgb(255,255,255)) 
     ); 
     box-shadow: 0px 1px 5px rgba(0,0,0,1); 
     height: 50px; 
     z-index: 1; 
    } 

.banner { 
    background-image:url('images/grad.jpg'); 
    background-color:#cccccc; 
    height: 500px; 
    z-index: -1; 
} 

但這不適用於我。

標記>

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Design Test | PolyDevs</title> 
<link rel="stylesheet" type="text/css" href="style.css"> 
<div class="header"> 
    <div class="title"> 
     <div class="logo"> 
      <img src="images/banner.png"/> 
     </div> 
    </div> 
</div> 
</head> 
<body> 
<div class="banner"> 

</div> 
</body> 
</html> 
+0

請發佈您的HTML –

+0

你能分享你的標記(HTML)嗎? 'z-index'是[設置相對](http://stackoverflow.com/questions/7482840/z-index-order-for-draggable-div/7482870#7482870)所以你的標記很重要... –

+0

是父母橫幅設置爲'position:relative'的元素?我知道這是絆倒了我過去 – aviemet

回答

0

位置:相對;解決了我的問題,爲什麼呢?

絕對定位的元素表現爲由相對定位的一個父元素定位。

如果沒有元件相對於定位,則<body>元件,即由位於默認相對的,將成爲指定「從」位置的父(左,右,下,頂部

例如:

<body> 
<div class="posrelative"> 
    <div class="posabsolute">hello world</div> 
</div> 
</body> 

世界,你好基於其中母公司包裝<div>再也定位絕對的,這可能是側邊欄或頁腳等

<body> 
<div> 
    <div class="posabsolute">hello world</div> 
</div> 
</body> 

世界,你好現在可以定位絕對的,但現在不是了基於從父<div>的位置,但基於關閉<body>的位置,這填補了瀏覽器窗口的整個寬度默認爲