![](/img/trans.png)
[英]CSS: using div and background image, image not resizing to fit div size
[英]Issue resizing a div background image with CSS
我正在使用網站的草稿版本,該版本使用比原始樣式更敏感的設計,並且遇到使我的CSS滾動效果導航欄按鈕正確調整大小的問題。 我可以讓div調整大小,但不能調整.png圖像本身。
以下是“主頁”按鈕的代碼。 我將div的大小調整為11.5%,因為當它顯示在其他按鈕旁邊時,它們都具有唯一的大小,並且非常適合父div。
任何幫助,不勝感激:)感謝您的光臨!
#homebut
{
display:inline-block;
width:158px;
height:40px;
max-width:11.5%;
max-height:100%;
text-align:center;
background:url(images/buttons/wawhomeroll.png) no-repeat 0 0;
background-position:center top;
background-size:auto;
}
#homebut:hover
{
background-position:0 -40px;
background-position:center bottom;
}
#homebut: span
{
position:absolute;
top: -999em;
}
作為評論background-size:100% auto;
#homebut {
display:inline-block;
width:158px;
height:40px;
max-width:11.5%;
max-height:100%;
text-align:center;
background:url(images/buttons/wawhomeroll.png) no-repeat 0 0;
background-position:center top;
background-size:100% auto;
}
嘗試background-size: cover;
。
Cover此關鍵字指定在確保背景圖像尺寸均大於或等於背景定位區域的相應尺寸的同時,將背景圖像縮放至盡可能小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.