我有一個圖像背景,我想要在不同的設備上顯示div,問題是我必須給圖像的高度以正確適合它。現在在不同的手機上,我必須用不同的像素來調整高度。例如在iphone 65px的作品肖像模式,但不適用於風景等。有沒有一種方法,div只是被調整高度以覆蓋100%的背景圖像? 這裏是我的代碼用於媒體查詢和高度問題的css
<style>
div.testing {
height: 95px;
background-image: url(/myimageurl);
background-repeat: no-repeat;
background-size: 100%;
}
@media screen and (max-width: 320px) {
/* iphone portrait */
div.testing {
height: 65px;
}
}
@media screen and (min-width: 321px) and (max-width: 480px) {
/* iphone portrait */
div.testing {
height: 80px;
}
}
</style>
<div class="testing"> </div>
如果我使用背景大小:封面然後寬度成爲一個問題 – Autolycus