[英]CSS3 - Width:100% - Height:Auto - Background-image?
为主体分配背景,如下所示:
body{
background-image: url('../img/yourimagefilename.jpg');
background-position: top center;
background-attachment: fixed;
background-repeat: no-repeat;
background-size: cover;
background-color: #343433;
height: 100%;
}
这是用覆盖视口宽度的背景图像创建英雄横幅的另一种方法:
http://codepen.io/anon/pen/IknKF
的HTML
<div class="hero">
<img src="http://zerostrikes.com/demo/momentum/images/bg-1.jpg" alt="" />
<div class="logo">
<h1>LOGO</h1>
</div>
</div>
的CSS
body {
margin: 0;
padding: 0;
}
.hero img {
width: 100%;
}
.logo h1 {
position: absolute;
top: 300px;
right: 50%;
color: white;
}
那应该让您有一个响应式图像作为背景。 为了使站点真正具有响应性,如您在上面提到的示例中,请阅读有关媒体查询的信息。 这是Smashing Magazine的一个很好的教程,解释了媒体查询的基础:
首先,将<div class="background">
放在标题之外。
然后在您的CSS中添加以下内容:
.background{
background:url('http://www.md-esign.be/images/hdbg.png') 50% 50% no-repeat;
height:400px;
background-size:cover;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.