【问题标题】:Why don't I have a scroll bar?为什么我没有滚动条?
【发布时间】:2012-12-11 08:00:28
【问题描述】:

我正在用 HTML、CSS 和 PHP 创建一个网站,页面超出了屏幕范围,但浏览器没有提供滚动条(Mac 上的 Safari 5.0.6 和 Firefox 14.0.1)。是因为我包含了 PHP 吗?但是在页面渲染之前不应该在那里吗?

这是一个链接:test website

我的 PHP 语法:

<div id="content">
        <div class="wrapper">
            <div id="home" class="alert">
                Welcome to always4free&copy;! To browse the classifieds, you must first either choose a location or have your location detected.
            </div>
            <?php include "res/pages/categories.php"; ?>
        </div>
    </div>
</div>

发生了什么事?

编辑:这是我的 CSS:

    body {
    background-image: url("http://always4free.org/site/images/bg.jpg");
    background-size: cover;
    font-family: "Mouse Memoirs",sans-serif;
}
.wrapper {
    margin: 0 auto;
    width: 850px;
}
#header {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.5);
    border-bottom: 3px solid green;
    box-shadow: 0 2px 10px #888888;
    height: 50px;
    left: 0;
    position: fixed;
    top: 0;
    width: 100%;
}
#logo {
    color: rgba(255, 255, 255, 0.7);
    float: left;
    font-family: "Wendy One",sans-serif;
    font-size: 30px;
    line-height: 50px;
    width: 250px;
}
#logo a:hover {
    color: #FFFFFF;
}
#nav {
    float: right;
    line-height: 50px;
    width: 600px;
}
#nav a:first-child {
    margin-left: 0;
}
#nav a:last-child {
    margin-right: 0;
}
#nav a:link, #nav a:visited {
    color: rgba(255, 255, 255, 0.9);
    font-family: "Mouse Memoirs",sans-serif;
    letter-spacing: 1px;
    margin-left: 10px;
    margin-right: 10px;
}
#nav a:hover {
    border-bottom: 2px solid #FFFFFF;
    color: #FFFFFF;
    padding-bottom: 1px;
}
#nav a.detect {
    background-color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 2px 2px 2px 2px;
    color: rgba(0, 0, 0, 0.7);
    padding: 5px;
}
#nav a.detect:hover {
    color: #000000;
}
#content {
    font-family: "Mouse Memoirs",sans-serif;
    letter-spacing: 1px;
    margin-top: 70px;
}
.page {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.5);
    border: 1px solid green;
    color: #FFFFFF;
    font-size: 20px;
    padding: 10px;
}
.alert {
    background: none repeat scroll 0 0 #AD2E1D;
    border: 1px solid #911E0F;
    color: white;
    font-size: 20px;
    padding: 10px;
    text-align: center;
}
#categories {
    margin-top: 20px;
}
#categories h2 {
    color: rgba(255, 255, 255, 0.7);
    font-family: "Wendy One",sans-serif;
    font-size: 26px;
}
#categories a:link, #categories a:visited {
    background: none repeat scroll 0 0 white;
    color: black;
    padding: 3px;
}
#categories .block {
    line-height: 35px;
}

【问题讨论】:

  • 检查你是否有overflow:scroll; css 属性
  • 我添加了这个,但什么也没发生。白条出现在它们应该出现的位置,但没有滚动条。

标签: php html css


【解决方案1】:

您的所有内容都包含在position: fixed; 的元素中。 body 无法检索固定或绝对子项的高度,因此设置为实际高度 0 - 从而消除了任何滚动需求。

如果您将 #content 元素移到固定标题之外,则应该可以按预期工作。

【讨论】:

    【解决方案2】:

    将 ID 为 content 的 div 移到 header div 之外。

    它会解决你的问题。

    【讨论】:

    • 我不敢相信我没有注意到这一点!谢谢!
    【解决方案3】:

    在您的 .wrapper 中添加一个 clearfix 类,使其具有高度,然后使用:

    .wrapper{
        overflow: scroll;
    }
    

    【讨论】:

    • 白条出现在它们应该出现的位置,但没有滚动条。不过我不知道为什么!
    • 我已经编辑了我的答案,请使用 .clearfix 然后再试一次。
    【解决方案4】:

    在您的#header 样式中添加overflow:scroll;,并将位置更改为relative。

    #header {
        background: none repeat scroll 0 0 rgba(0, 0, 0, 0.5);
        border-bottom: 3px solid green;
        box-shadow: 0 2px 10px #888888;
        height: 50px;
        left: 0;
        position: **relative**;
        top: 0;
        width: 100%;
        **overflow: scroll;**
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      相关资源
      最近更新 更多