html - 如何在缩小窗口时创建水平滚动条

标签 html css

如果我有一个宽度为 1225px 的内容区域,我该如何制作,以便当您将页面缩小到小于该宽度时,会出现水平滚动条,以便中心内容始终可见(至少具有滚动选项)?是否涉及使用固定或绝对定位?

在这个网站中,你可以看到当你缩小页面时,会出现水平滚动条:http://www.websitecodetutorials.com/

我不知道这是否有帮助,但这是我的一些代码:

<body class="fullbackground">
    <img class="fullbackground" src="background.png" />
    <div class="topbackground">
            <div class="top">
                <div class="topleft">
                    <img class="pf_logo" src="pathfinder_logo.png"/>
                </div>
                <div class="topmiddle">
                    <h1 class="title">Pathfinder is Temporarily Unavailable</h1>
                </div>
                <div class="topright" ></div>
            </div>
        </div>
        <div class="bar"></div>
        <div style="width:1225px; height:870px; padding-top:0px; margin-top:0px; margin-left:auto; margin-right:auto;">
        <div class="contentcontainer">

我使用了 CSS 重置。这是我的一些 CSS:

.bar {
    background-color:#365C8C;
    height:30px;
    width:auto;
    position:relative;
    padding:0 0 0 0;
    margin:0 0 0 0;
    overflow-x:hidden; 
}

body {
    position:relative;
    padding:0 0 0 0;
    margin:0 0 0 0;
    overflow-x:hidden;
    height:100%;
    width:100%;
    background-color:#ADCCEB;
    /*background-color:black;*/
    /*background: url(background.png);*
    /*background-size:100%;*/
}

.bold {
    font-weight:bold;
}

.contentcontainer {
    width:825px;
    height:870px;
    margin-left:auto;
    margin-right:auto;
    margin-top:0px;
    padding-top:0px;
    /*background-color:red;*/
}

.extcontentcontainer {
    width:825px;
    height:645px;
    margin-left:auto;
    margin-right:auto;
    margin-top:0px;
    padding-top:0px;
    /*background-color:red;*/
}

img.fullbackground {
    position:absolute;
    z-index:-1;
    top:0;
    left:0;
    width:100%; 
    height:100%;
    padding: 0 0 0 0;
    margin: 0 0 0 0;
}

img.extfullbackground {
    position:absolute;
    z-index:-1;
    top:0;
    left:0;
    width:100%; 
    height:100%; 
    padding: 0 0 0 0;
    margin: 0 0 0 0;
}

最佳答案

您可以尝试将此属性添加到 body 标记中:

溢出-x:自动;

关于html - 如何在缩小窗口时创建水平滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17111507/

相关文章:

javascript - 显示具有固定宽度和高度的图像而不会变形/扭曲

html - 为什么我不能用 bootstrap 改变背景?

php - 从 DB html/css 显示的 500 个结果丢失格式

html - 如何减少行标题之间的空白

javascript - 在 Bootstrap 中显示隐藏特定的 li

css - 如何右对齐图表

javascript - 在没有 parent 和 child 的其他选择器上设置可见

html - 切换 CSS 文件时保留旧显示值

jquery - 输入类型编号我们可以停止编辑并使用下拉/下拉更改值吗

css - 更少的编译器使一切翻倍