我有一个容器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