Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Div内有背景图像的Div不';我不能正常工作_Html_Css_Background - Fatal编程技术网

Html Div内有背景图像的Div不';我不能正常工作

Html Div内有背景图像的Div不';我不能正常工作,html,css,background,Html,Css,Background,我有一个div,背景图像放在另一个div中,而不是fit-width父div,它适合全屏。请看一下我的代码,以清楚地知道,对不起,英语不好 HTML <div id="video-section" class="dark-section"> <div class="home"></div> <div class="fullscreen-img" style="background-image: url(http://upanh.biz/im

我有一个div,背景图像放在另一个div中,而不是fit-width父div,它适合全屏。请看一下我的代码,以清楚地知道,对不起,英语不好

HTML

<div id="video-section" class="dark-section">
  <div class="home"></div>
    <div class="fullscreen-img" style="background-image: url(http://upanh.biz/images/2014/11/23/bg1.jpg)"></div>
</div>

提前感谢。

需要绝对定位
.home
div,以避免向下“推”背景div。后台div不应该有
全屏img
类,因为大多数规则都应该删除。它只需要
height:100%
,因为div是块元素,所以默认情况下具有
width:100%
。当然,将内联样式移动到类或ID规则中,我将它们放在那里只是为了向您展示

基本上,这就是您所需要的:

  • 从后台div中删除
    .fullscreen img
  • 将其高度改为100%
  • 使
    .home
    div处于绝对位置

请看这里:

*{
保证金:0;
填充:0;
}
身体{
背景色:黑色;
}
#视频部分{
保证金:0自动;
宽度:1230px;
高度:500px;
}
.暗区{
背景色:黑色;
}
.家{
显示:表格;
高度:500px;
左:0;
位置:绝对位置;
排名:0;
宽度:100%;
}


你是说为什么
.fullscreen img
div适合全屏显示?:)是的,我如何修理它?:)之所以全屏显示,是因为位置:固定。这使得div定位和尺寸是相对于视口而不是其父视口计算的。你想要什么效果?我正在使用mb.YTPlayer插件创建视频背景。我想尝试的效果就像这里的顶级视频:。但他们的网站布局是全屏的,而我的网站布局是盒装的。我不知道如何表达我的意见,但我可以把我的邮政编码发给你检查。嗯,它看起来很混乱,我甚至不知道该看哪个部分。对不起,这部分是“上周五派对”,背景适合全屏。在那里,我添加了两个修改,你需要应用到有问题的元素。谢谢,但我还有一个问题,当向下滚动时,图像也会向下滚动。我怎么修理它?
*{
  margin: 0;
  padding: 0;
}

#video-section{
  margin: 0 auto;
  width: 1230px;
  height: 500px;
}

.dark-section{
  background-color: black;
}

.home{
    display: table;
    height: 500px;
    left: 0;
    position: relative;
    top: 0;
    width: 100%;
}

.fullscreen-img {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    height: auto;
    left: 0;
    min-height: 500px;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: -1;
}