一:
HTML部分
<div class="article-top"></div>
CSS部分
.article-top {
background: url("img/3.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
二:
HTML部分
<div class="article-top" style="background: url('img/3.jpg');"></div>
CSS部分
.article-top {
/*background: url("img/3.jpg");*/
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
为什么第二种情况把 background-image
放到 div 里面后 background-repeat
background-position
background-size
等等会失效呢?
第二部分的style应该使用 background-image 属性。