Html 背景图像未显示在div中
我已经尝试了一切,但不明白为什么我不能让背景图像显示在这个div中Html 背景图像未显示在div中,html,css,image,background,background-image,Html,Css,Image,Background,Background Image,我已经尝试了一切,但不明白为什么我不能让背景图像显示在这个div中 **Here is the code:** 正文{ 边际:0px; 填充:0px; } #顶{ 背景图片:url(../IMG/PINS.jpg)无重复中心固定; -webkit背景尺寸:封面; -moz背景尺寸:封面; -o-背景尺寸:封面; 背景尺寸:封面; } 测试BCKGRND映像 您需要从#top设置高度和宽度值,并使用背景位置:居中;背景重复:无重复喜欢我的答案:例如 #top{ width:500px;
**Here is the code:**
正文{
边际:0px;
填充:0px;
}
#顶{
背景图片:url(../IMG/PINS.jpg)无重复中心固定;
-webkit背景尺寸:封面;
-moz背景尺寸:封面;
-o-背景尺寸:封面;
背景尺寸:封面;
}
测试BCKGRND映像
您需要从#top
设置高度和宽度值,并使用背景位置:居中;背景重复:无重复代码>喜欢我的答案:例如
#top{
width:500px;
height:500px;
background-image: url(YOUR IMAGE PATH);
background-repeat:no-repeat;
background-position:center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
或者你可以这样做:
#top{
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background:url(YOUR IMAGE PATH) no-repeat fixed center;
width:500px;height:500px;
}
这是因为你的div是空的。如果您添加内容,那么您将看到背景。您还可以使用CSS设置高度或添加填充
<div id="top">
<p>A large amount of text here</p>
</div>
或
设置#top
div的高度很重要:如果先将宽度设置为“自动”,然后将高度设置为“自动”,则背景仍然不会显示,因为div中没有可放置背景的内容。但是,如果通过在css中设置一个高度来强制设置一个高度,则会显示背景。
您为路径提供的代码不正确,因为背景图像
只需要图像的路径(而不需要其他路径),而您提供的代码适用于背景
请参阅我的很高兴为您提供帮助!:)
#top{
height:400px;
background-image: url(yourimagehere);
background-repeat:no-repeat;
background-position:center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#top{
padding: 25px 0;
background-image: url(yourimagehere);
background-repeat:no-repeat;
background-position:center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}