很多人都問過類似的問題,但我找不到它們如何具體適用于我的情況。
.container {
margin: 0 auto;
background-image: url('https://images.unsplash.com/photo-1539683255143-73a6b838b106?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80') no-repeat;
background-size: 100px;
}
<div class="container">
</div>
我是否需要在 div 中添加一些內容以使其顯示?我想如果我只是制作一個 div 并定義它會起作用的寬度,但我很難過。而且我知道這是我想念的超級簡單的東西
uj5u.com熱心網友回復:
您必須為容器指定寬度和高度。并洗掉 no-repeat 并添加此背景重復: no-repeat;
uj5u.com熱心網友回復:
它導致了no-repeat第一個問題,不允許將值應用于background-image,并且container在此示例中您沒有高度,您需要指定它或將內容添加到container
.container {
margin: 0 auto;
background-image: url('https://images.unsplash.com/photo-1539683255143-73a6b838b106?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80');
background-size: 100px;
background-repeat: no-repeat;
min-height: 100px;
}
<div class="container">
</div>
uj5u.com熱心網友回復:
您需要添加高度,并且需要從background-image宣告中洗掉“不重復”。我們可以使用一個宣告background-repeat來代替。
.container {
/* added these next 2 lines, and remove 'no-repeat' from the background-image */
height:200px;
background-repeat: no-repeat;
width: 200px;
margin: 0 auto;
background-image: url('https://images.unsplash.com/photo-1539683255143-73a6b838b106?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80');
background-size: 100px;
}
<div class="container">
</div>
uj5u.com熱心網友回復:
.container {
margin: 0 auto;
background: url('https://images.unsplash.com/photo-1539683255143-73a6b838b106?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1000&q=80') no-repeat;
background-size: 100px;
height: 151px;
width: 100px;
}
<div class="container"></div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/517447.html
標籤:htmlcss背景图片
上一篇:為什么單擊按鈕后函式不執行?
