我有一個背景圖像div放在另一個div裏,而不是適合寬度父div,它適合全屏幕。請看看我的代碼清楚地知道,對不起英文不好。Div與背景圖像裏面div不能正常工作
http://codepen.io/thehung1724/full/jEEgQq/
HTML
<div id="video-section" class="dark-section">
<div class="home"></div>
<div class="fullscreen-img" style="background-image: url(http://upanh.biz/images/2014/11/23/bg1.jpg)"></div>
</div>
CSS
*{
margin: 0;
padding: 0;
}
#video-section{
margin: 0 auto;
width: 1230px;
height: 500px;
}
.dark-section{
background-color: black;
}
.home{
display: table;
height: 500px;
left: 0;
position: relative;
top: 0;
width: 100%;
}
.fullscreen-img {
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
height: auto;
left: 0;
min-height: 500px;
position: fixed;
top: 0;
width: 100%;
z-index: -1;
}
預先感謝。
你的意思是爲什麼'.fullscreen-img' div適合全屏幕? :) – Shomz 2014-11-23 15:59:50
是的,我該如何解決它? :) – 2014-11-23 16:08:30
它是全屏幕的原因是因爲位置:固定。這使得它的div定位和尺寸是相對於視口而不是它的父親來計算的。你要做什麼? – peterjb 2014-11-23 16:13:29