html - 为什么我的 body 比内容更宽?

标签 html css

我完全没有想法...抱歉,我还不能发布图片。所以,我正在制作一个网站,出于某种原因, body 总是比内容更宽。我似乎找不到原因。当我在 Chrome Dome 中检查它时,它甚至没有被标记为实际主体。

html {
height:100%;
width:100%;
}

body {
    background: black;
    margin:0;
    padding:0;
    position: relative;
    height: auto;
    min-height: 100% !important;
    font-size: 95%;
    display:block;
    width: 100%;
    overflow:auto;
}
.nav {
    background: #6192ec;
    height: 50px;
    width: 100%;
    text-align: center;
}

.nav nav{
    width: 100%;
    line-height: 2.2;
    margin: 0 auto;
    margin-left: 4%;
    vertical-align: top;
    display: inline-block;
}

.nav nav a {
    font-family: Oxygen;
    font-size: 140%;
    list-style: none;
    color: #283040;
    text-decoration: none;
    padding: 0 60px 0 0;

}

.nav ul {
    position: relative;
    display: inline;
    padding: 0;
}

.nav nav ul li {
    display: inline-block;
}

这是完整的代码。如果你能找到什么... 感谢您提出任何建议,并在此先感谢您阅读本文!

最佳答案

您的导航栏正在推出内容:

.nav nav{
  width: 100%;            // stretch to entire width
  line-height: 2.2;
  margin: 0 auto;
  margin-left: 4%;        // and start 4% away from the edge
  vertical-align: top;
  display: inline-block;
}

去掉margin-left,设置margin: 0;

html {
height:100%;
width:100%;
}

body {
    background: black;
    margin:0;
    padding:0;
    position: relative;
    height: auto;
    min-height: 100% !important;
    font-size: 95%;
    display:block;
    width: 100%;
    overflow:auto;
}

a {
    text-decoration: none;
}

.container {
    background: #fff url("/Users/sophie/Dropbox/Projects/TeneriffaBlog/imgsrc/pattern-9xhd.png") repeat;
    min-height:100%;
    position:relative;

}
.header {
    background: #3b3c3f;
    height: 80px;
}

.header img {
    height: 60px;
    width: auto;
    float: left;
    padding-left: 50px;
    padding-top: 10px;
}

.header h1 {
    float: left;
    margin: 0 1%;
}

.header a, a:active, a:visited {
    font-family: Vollkorn;
    font-weight: normal;
    letter-spacing: 1px;
    line-height: 2.4;
    font-size: 110%;
    color: #e6e6e6;
}

.nav {
    background: #6192ec;
    height: 50px;
    width: 100%;
    text-align: center;
}

.nav nav{
    width: 100%;
    line-height: 2.2;
    margin: 0;
    vertical-align: top;
    display: inline-block;
}

.nav nav a {
    font-family: Oxygen;
    font-size: 140%;
    list-style: none;
    color: #283040;
    text-decoration: none;
    padding: 0 60px 0 0;

}

.nav ul {
    position: relative;
    display: inline;
    padding: 0;
}

.nav nav ul li {
    display: inline-block;
}

.nav ul li .activeArrow {
    width: 0px;
    height: 0px;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 10px solid #f7f7f7;
    margin: -8px 0 0 20px;
}

.searchbar {
    float: right;
    margin: 0 2%;
    line-height: 5.5;
}

.searchbar input {
    font-family: Arial,sans-serif;
    color: #909cb2;
    font-size: 110%;
    font-style: italic;
    border: 1px solid #6192ec;
    border-radius: 3px;
    background-color: #fff;
    height: 30px;
    width: 300px;
    padding: 3px;
}

.searchbar input.sBtn {
    height: 38px;
    width: 75px;
}

.impressum {
    color: #8c8686;
    font-family: 'Lato',arial,sans-serif;
    font-size: 12px;
    text-align: left;
    height: 80px;
    width: auto;
    line-height: 80px;
    float: left;
    padding-left: 19%;
}

.credit {
    color: #8c8686;
    font-family: 'Lato',arial,sans-serif;
    font-size: 12px;
    text-align: left;
    height: 80px;
    width: auto;
    line-height: 80px;
    float: right;
    padding-right: 20%;
}

.impressum ul, li {
    text-decoration: none;
    list-style: none;
    display: inline;
    padding: 0 6px;
}

.impressum a {
    color: #8c8686;
    font-family: 'Lato',arial,sans-serif;
    font-size: 12px;
}

.content {
    background: none;
    width: 100%;
    height: 100%;
    overflow: auto;
    display: block;
    padding-bottom: 80px;   /* Height of the footer element */
}

.content {
    color: 661128;
    font-family: 'Lato', arial, sans-serif;
    text-align: center;
}

.welcome {
    float: right;
    width: 57%;
}

.hikeList {
    position: relative;
    background: #eff1f8 url("/Users/sophie/Dropbox/Projects/TeneriffaBlog/imgsrc/bg.png");
    border-right: 1px solid #a0b6c9;
    float: left;
    width: 24.9%;
    min-height: 100%;
    height: 100%;
}

.hikeList ul {
    overflow: scroll;
}

.hikeList ul li {
    display: list-item;
}

.footer {
    width:100%;
    height:80px;
    position:absolute;
    bottom:0;
    left:0;
    background: #3b3c3f;
}
   <div class="container">
        <div class="header">
            <img src="/Users/sophie/Dropbox/Projects/TeneriffaBlog/imgsrc/favicon.png" alt="icon">
            <h1><a href="#">ABC <i>DEF</i> HIJ <i>KLM</i></a></h1>
            <article class="searchbar">
                <form id="tfnewsearch" method="get" action="http://www.google.com">
                    <input type="text" id="tfq2b" class="tftextinput2" name="q" size="21" maxlength="120" value="Suchen Sie auf unserer Website">
                    <input type="submit" value="Suchen" class="sBtn">
                </form>
            </article>
        </div>
        <div class="nav">
        <nav>
            <ul>
                <li>
                    <a href="#">Home</a>
                    <div class="activeArrow"></div>
                </li>
                <li><a href="#">Grundregeln</a></li>
                <li><a href="#">Wanderungen</a></li>
                <li><a href="#">Links</a></li>
            </ul>
        </nav>  
        </div>

        <div class="content">
            <div class="hikeList">
                <ul>
                    <li><a href="">Item 1</a></li>
                    <li><a href="">Item 2</a></li>
                    <li><a href="">Item 3</a></li>
                    <li><a href="">Item 4</a></li>
                    <li><a href="">Item 5</a></li>
                    <li><a href="">Item 6</a></li>
                    <li><a href="">Item 7</a></li>
                    <li><a href="">Item 8</a></li>
                    <li><a href="">Item 9</a></li>
                    <li><a href="">Item 10</a></li>
                    <li><a href="">Item 11</a></li>
                    <li><a href="">Item 12</a></li>
                    <li><a href="">Item 13</a></li>
                    <li><a href="">Item 14</a></li>
                    <li><a href="">Item 15</a></li>
                    <li><a href="">Item 16</a></li>
                    <li><a href="">Item 17</a></li>
                    <li><a href="">Item 18</a></li>
                    <li><a href="">Item 19</a></li>
                    <li><a href="">Item 20</a></li>
                    <li><a href="">Item 21</a></li>
                    <li><a href="">Item 22</a></li>
                    <li><a href="">Item 23</a></li>
                    <li><a href="">Item 24</a></li>
                    <li><a href="">Item 25</a></li>
                    <li><a href="">Item 26</a></li>
                    <li><a href="">Item 27</a></li>
                    <li><a href="">Item 28</a></li>
                    <li><a href="">Item 29</a></li>
                    <li><a href="">Item 30</a></li>
                    <li><a href="">Item 31</a></li>
                    <li><a href="">Item 32</a></li>
                    <li><a href="">Item 33</a></li>
                    <li><a href="">Item 34</a></li>
                    <li><a href="">Item 35</a></li>
                    <li><a href="">Item 36</a></li>
                    <li><a href="">Item 37</a></li>
                    <li><a href="">Item 38</a></li>
                    <li><a href="">Item 39</a></li>
                    <li><a href="">Item 40</a></li>
                    <li><a href="">Item 41</a></li>
                    <li><a href="">Item 42</a></li>
                    <li><a href="">Item 43</a></li>
                    <li><a href="">Item 44</a></li>
                    <li><a href="">Item 45</a></li>
                    <li><a href="">Item 46</a></li>
                    <li><a href="">Item 47</a></li>
                    <li><a href="">Item 48</a></li>
                    <li><a href="">Item 49</a></li>
                    <li><a href="">Item 50</a></li>
                </ul>
            </div>

            <div class="welcome">
                <div class="headImg">

                </div>
                <h2>Welcome</h2>
                <article>
                    welcome text
                </article>
            </div>


            </div> 

        </div>
        <div class="footer">
            <div class="impressum">
                <li>
                    <ul><a href="#">About</a></ul>
                    <ul>|</ul>
                    <ul><a href="#">Contact</a></ul>
                    <ul>|</ul>
                    <ul><a href="">Impressum</a></ul>
                </li>
            </div>

            <div class="credit">
                Blup
            </div>
        </div>




    </div>  

关于html - 为什么我的 body 比内容更宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27324929/

相关文章:

javascript - 他们是一种让一个 div 只在另一个 div 中可见的方法吗?

.net - 我可以将一幅图像的白色(默认)背景替换为另一幅图像吗?

angular - 为什么用户无法编辑该引导表?

javascript - 使用javascript获取相对于监视器的元素位置

hover - 如何让菜单从左到右堆叠但不挤压其内容

jquery - 如何使用CSS根据图像的宽度响应式地设置按钮的宽度

javascript - 创建与窗口成比例大小的圆

php - 使用 Ajax 调用检索数据时出错

jquery - 当 jQuery 添加其他 <li> 时,下拉菜单宽度会发生变化

html - Angular material 2 table - 使用 TemplateRef 和 ngTemplateOutlet 定义列