2017-05-29 42 views
0

問題:修復CSS所以它是相對於它的孩子(/響應)

現在頭部大小是靜態的。例如,如果我想更改圖像大小或更改我的設備,它會與我的基礎導航相沖突(在這種情況下,由於其絕對標籤,導航只是在圖像下方)。

如何將此標題更改爲響應,而圖像仍在彼此之上(前面和bg)?

HTML

  <div class="header-parallax"> 
       <div class="box fore-box"> 
        <div class="img fore"></div> 
       </div> 
       <div class="box bg-box"> 
        <div class="img bg"></div> 
       </div> 
      </div> 

造型

.header { 
    position: relative; 
    height: 518.75px; 
    width: 100%; 
} 

.header-parallax { 
    padding: 20px 20px 20px 20px; 
} 

* { 
    box-sizing: border-box; 
} 

.box { 
    position: absolute; 
    perspective: 400px; 
    width: 750px; 
    height: 478.75px; 
    overflow: hidden; 
    transform-style: preserve-3d; 
    transition: perspective 5s; 
} 

.fore-box { 
    z-index: 10; 
} 

.bg-box { 
    z-index: 5; 
} 

.img { 
    top: 0; 
    left: 0; 
    width: 750px; 
    height: 478.75px; 
    transition: all 5s; 
} 

.fore { 
    z-index: 10; 
    background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/9332/hills-foreground.png); 
    background-size: cover; 
} 

.bg { 
    background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/9332/hills-bg.jpg); 
    transform: translateZ(150px); 
    background-size: cover; 
    filter: blur(2px); 
} 

.box.on .fore { 
    transform: translateZ(200px); 
filter: blur(1px); 
} 
.box.on .bg { 
    transform: translateZ(0); 
    filter: blur(0px); 
} 

在瀏覽圖片的是: Parallax Header

回答

0

希望這將幫助你

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<style> 
 
.header { 
 
    position: relative; 
 
    height: 518.75px; 
 
    width: 100%; 
 
} 
 

 
.header-parallax { 
 
    padding: 20px 20px 20px 20px; 
 
} 
 

 
* { 
 
    box-sizing: border-box; 
 
} 
 

 
.box { 
 
    position: absolute; 
 
    perspective: 400px; 
 
    width: 750px; 
 
    height: 478.75px; 
 
    overflow: hidden; 
 
    transform-style: preserve-3d; 
 
    transition: perspective 5s; 
 
} 
 

 
.fore-box { 
 
    z-index: 10; 
 
} 
 

 
.bg-box { 
 
    z-index: 5; 
 
} 
 

 
.img { 
 
    top: 0; 
 
    left: 0; 
 
    width: 750px; 
 
    height: 478.75px; 
 
    transition: all 5s; 
 
} 
 

 
.fore { 
 
    z-index: 10; 
 
    background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/9332/hills-foreground.png); 
 
    background-size: cover; 
 
} 
 

 
.bg { 
 
    background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/9332/hills-bg.jpg); 
 
    transform: translateZ(150px); 
 
    background-size: cover; 
 
    filter: blur(2px); 
 
} 
 

 
.box.on .fore { 
 
    transform: translateZ(200px); 
 
filter: blur(1px); 
 
} 
 
.box.on .bg { 
 
    transform: translateZ(0); 
 
    filter: blur(0px); 
 
} 
 
.header-parallax{ 
 
    background: red; 
 
    position: fixed; 
 
    width: 100%; 
 
    z-index: 999; 
 
} 
 
</style> 
 
</head> 
 
<body> 
 
<div class="header-parallax"> 
 
       
 
      </div> 
 
      <div class="box fore-box"> 
 
        <div class="img fore"></div> 
 
       </div> 
 
       <div class="box bg-box"> 
 
        <div class="img bg"></div> 
 
       </div> 
 
</body> 
 
</html>

相關問題