我有一個容器div(.tablet)。兩個部分和DIV響應DIV崩潰背景圖像
當視圖端口達到> 400像素,我想在div來顯示背景圖像(.tablet)
然而,除非我指定一個像素的寬度和高度,在div塌陷並消失。它忽略了背景圖像。這幾乎就像背景圖片不存在,div沒有內容!
是否有可能創建一個靈活的背景圖像,不崩潰的resposnive DIV?我想要背景圖片填充DIV並以div大小進行響應?
我已經使用以下規則與.tabletonly DIV試圖
background-size: cover;
background-position: center;
background-attachment: fixed; /* Fixbackground * */
// ------------------------ --------------------------------------------
HTML
<!DOCTYPE html PUBLIC>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles/style1.css"/>
</head>
<body>
<div id="wrapper">
<div id="section">
<div id="tabletonly" class="span_1_of_2">
<div><div>
</div>
</div> // end wrapper
</body>
</html>
CSS code ----------------------------------------
.span_1_of_2 {
width: 45%;
position: relative;
}
img {
max-width: 100%;
}
@media screen and (min-width: 400px) {
#tabletonly div{
background: url("images/shop.jpg");
background-repeat: no-repeat;
}
}
nb。背景圖片就是那個,背景而不是內容。因此,它受到應用元素的尺寸的限制。您將需要將尺寸應用於'.tablet',或者,而不是使用背景圖像,切換「img'元素的顯示 – SW4
如果您沒有在div中放入任何東西,只需使用IMG標記並交換那些了。 – jleggio