如果我使用background-size:contain;
,当浏览器尺寸发生变化时如何消除空白?
图片和文本之间的空格太大,浏览器尺寸较小。网站是:http://16debut.com/test.html
CSS是:
body {
margin:0px 0px;
}
#hero {
background-clip: content-box;
background-image: url("imgtop.png");
background-size: contain;
background-repeat: no-repeat;
position: relative;
height: 235vh;
}
#content {
padding: 100px 50px;
text-align: center;
width: 80%;
margin: 0px auto;
}
#content h2 {
margin: 0px 0px 30px 0px;
}
#footer {
padding: 30px 0px;
text-align: center;
background: #ddd;
}
答案 0 :(得分:2)
<强> jsbin demo 强>
你想要完全响应,但保持底部的白云?
对同一元素使用两个背景图片。
现在在CSS中:
background-position: bottom
和100%大小(“宽度”)50%
)位置和cover
CSS
html, body{height:100%; margin:0;}
#hero{
position:relative;
height:130vh; /* USE THE RIGHT RATIO since the image Logo is a bit up*/
background: no-repeat
url(http://i.stack.imgur.com/eWFn6.png) bottom / 100%, /* BOTTOM CLOUDS OVERLAY */
url(http://i.stack.imgur.com/IVgpV.png) 50% / cover; /* BIG IMAGE */
}
HTML
<div id="hero"></div>
<div class="other">
<h1>Other Divs</h1>
<p>bla bla</p>
</div>
似乎Safari是一个非常愚蠢的浏览器(他们甚至从2012年开始删除对Windows的支持......太棒了)。这是jsBin example和css:
#hero{
position:relative;
height: 900px;
height: 100vh;
background: url(http://i.stack.imgur.com/eWFn6.png) no-repeat bottom, url(http://i.stack.imgur.com/IVgpV.png) 50%;
background-size: 100%, cover;
}