【问题标题】:Body background extends past the html div正文背景超出 html div
【发布时间】:2014-02-17 20:12:58
【问题描述】:

我正在测试一个图像滑块,以在我的投资组合中实施。我将包含的 div(轮播)设置为 100% 宽度。但是,我仍然在 div 的右侧看到大约 200px 的主体背景颜色,这也导致出现水平滚动条。当我尝试检查页面上的元素时,我将 html div 视为轮播的宽度,但设置为 body 的背景颜色由于某种原因超出了此范围。

我已尝试更改定位和边距,但无法弄清楚我忽略了什么。这是大元素的css和页面http://marjib.com/test/test1.html

请有人帮忙:)


body { 
margin:0 auto;
background-color: #333;
}

.carousel {
margin:0;
width:100%;
height:630px;
background-color:#EEE;
position:absolute;
}

.slides {
padding: 0px;
width: 850px;
height: 630px;
margin: 20px auto;
position:relative;

}

.slides * {
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
}

.slides input { display: none; }

.slide-container { display: block; }

.slide {
top: 0;
opacity: 0;
width: 850px;
height: 556px;
display: block;
position: absolute;

transform: scale(0);

 transition: all .7s ease-in-out;
}

.slide img {
width: 100%;
height: 100%;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    你的.nav-dots 上的width:100% 删除它应该没问题。它在加载时占用文档的宽度,但是当您将其从左侧绝对定位到固定量时,它会将其推过正文宽度,从而导致额外的间距。

    【讨论】:

    • 仅在检查器窗口中对此进行了测试,但似乎有效。感谢双方的回复。这让我发疯了。
    【解决方案2】:

    更改您的 .nav-dots CSS

    .nav-dots {
        display: block;
        height: 11px;
        left: 360px;
        position: absolute;
        top: 580px;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 2011-05-02
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-17
      相关资源
      最近更新 更多