[英]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.