我使用圖像作爲背景,它完全適合。 當我嘗試調整屏幕大小(手機/平板電腦大小)時,圖像停留在後面,不像屏幕那樣縮小 - 不會變得響應。 我想改變這種效果,並使其響應並縮小尺寸屏幕。當屏幕尺寸減小時自動調整圖像尺寸
HTML:
<!-- Header -->
<header id="top" class="header">
<div class="text-vertical-center">
<h1>Test</h1>
<h3>The</h3>
<br>
<a id="show-panel" href="#" class="btn btn-dark btn-lg">Sign Up</a>
</div>
</header>
CSS:
/* Header */
.header {
display: table;
position: relative;
width: 100%;
height: 100%;
background: url(../img/coffee.jpg) no-repeat center center scroll;
color: #ffffff;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
不要設置'width'或'height'在你的CSS,而不是加上'背景重複:不重複; 背景尺寸:含有;背景位置:中心;' –
什麼是這個方法的優點? – drorAlfasi
這裏有一些很好的答案。爲什麼不接受一個? –