我想知道為什么這個(gè)CSS代碼顯示兩個(gè)相同的背景圖像,即使我只設(shè)置了一個(gè),下面是代碼:
html, body {
margin: 0;
padding: 0;
}
body {
font-family: 'Roboto', sans-serif;
font-weight: 100;
}
.container {
margin: 0 auto;
max-width: 940px;
padding: 0 10px;
}
/* Header */
.header {
height: 800px;
text-align: center;
background-repeat: no-repeat;
background: url(http://www.bolsamania.com/cine/wp- content/uploads/2016/07/9-2.jpg);
color: white;
padding: 100px;
background-repeat: no-repeat;
}
.header .container {
position: relative;
top: 200px;
}
.header h1 {
font-size: 80px;
line-height: 100px;
margin-top: 0;
margin-bottom: 80px;
}
@media (min-width:850px) {
.header h1 {
font-size: 120px;
}
}
.header p {
font-weight: 500;
letter-spacing: 8px;
margin-bottom: 40px;
margin-top: 0;
}
.btn:hover {
background: #117bff;
cursor: pointer;
transition: background .5s;
}
/* Nav */
.nav ul {
list-style: none;
margin: 0 auto;
padding: 30px 0;
text-align: center;
}
.nav ul li {
display: inline-block;
background-color: white;
padding: 1px 2px 1px 2px;
border: 1px solid black;
border-radius: 5px;
}
.nav {
background-color: black;
}
/* Main */
.main .container {
margin: 80px auto;
}
/* Jumbotron */
.jumbotron {
height: 600px;
text-align: right;
}
.jumbotron .container {
position: relative;
top: 220px;
}
/* Footer */
.footer {
font-size: 14px;
}
/* Media Queries */
@media (max-width: 500px) {
.header h1 {
font-size: 50px;
line-height: 64px;
}
.main, .jumbotron {
padding: 0 30px;
}
.main img {
width: 100%;
}
}
.btn {
border: 1px solid black;
text-decoration: none;
border-radius: 5px;
padding: 5px;
background-color: #808080;
color: white;
margin-bottom: 10px;
}
.main img {
float: left;
size: contain;
}
即使我添加了:背景-重復(fù):無-重復(fù),圖像也會(huì)重復(fù); 預(yù)先感謝你的幫助。
你也應(yīng)該能夠在這個(gè)鏈接中看到HTML和CSS的完整代碼:https://gist.github.com/2bc611f755c242271cb6984a0ed11cf7
再次感謝。
你在哪里添加背景重復(fù):不重復(fù)?如果你把它加在背景之前,那么它就不起作用了,因?yàn)楸尘八儆洉?huì)把它設(shè)置回重復(fù)。如果你在它后面加上它,它就會(huì)。
這讓我痛苦了幾次,所以我盡量避免背景速記。
經(jīng)過一些檢查后,問題是您的html中有兩個(gè)“header”元素:
<html>
<head>
<link rel='stylesheet' type='text/css'>
<div class=header>
<h1>INNOVATION CLOUD</h1>
<p>CONNECT YOUR IDEAS GLOBALLY</p>
<a href="#" class=btn>Learn More</a>
<link rel='stylesheet' href='style.css'/>
</div>
</head>
<body>
<div class="header">
<div class="container">
</div>
</div>
<div class="nav">
<ul>
<li>Register</li>
<li>Schedule</li>
<li>Sponsor</li>
<li>About</li>
<li>Contact</li>
</ul>
<div class="container">
</div>
</div>
<div class="main">
<img src="http://www.themarysue.com/wp-content/uploads/2015/12/Kylo_Ren.jpg" class=kylo/>
<div class="container">
<h2>The Innovation Cloud Conference</h2>
<p>Connect with the best minds across a wide range of industries to share ideas and brainstorm new solutions to challenging problems.</p>
<p>Hear industry leaders talk about what worked (and what didn't) so that you can save time on your most challenging projects.</p>
<p>Learn about the latest research and technologies that you can use immediately to invent the future.</p>
</div>
</div>
</body>
</html>
你好,只要去掉背景-尺寸:封面;并嘗試下面的代碼
header {
height: 800px;
text-align: center;
background: url(http://www.bolsamania.com/cine/wp-content/uploads/2016/07/9-2.jpg);
color: white;
padding: 100px;
background-repeat: no-repeat;
}
謝謝
你需要的是不重復(fù)。CSS背景-重復(fù)屬性
如果有人碰巧像我一樣需要它,并且是新手,我用兩種方法解決了這個(gè)問題,兩種方法都有效:
背景-尺寸:封面; 背景-重復(fù):無重復(fù)回合;