【问题标题】:Can't get scroll bar to appear on overflow无法让滚动条出现在溢出时
【发布时间】:2013-08-05 02:48:51
【问题描述】:

我正在构建一个 MDI WEB 应用程序,并有一个由 article 元素创建的窗口,其中包含一个 header 和一个 section 用于内容。由于它是一个 MDI 应用程序,article 设置为absolute,因此它可以与其他窗口重叠。我需要一个滚动条出现在内容部分,而不是 header

<article id="win3">
    <header> … </header>
    <section> … </section>
</article>

CSS:

article {
    position: absolute;
    min-width: 500px;   
    width: 918px;
    margin: 0px;
    padding: 0px;
    overflow: hidden; 
    background-color: white;
    border-style: ridge;
    border-color: #ddd;
    border-width: 4px;
}
article>section {
    /* reduce diameter of rounded corner to match the inside curve of the border */
    border-radius: 10px;
    -moz-border-radius: 10px;
    display: block;
    overflow: auto;
    border: none;
    width: 100%;
    background-color: white;
    padding: 10px 10px 10px 20px;
    min-height: 50px;
    height: 100%;
}

看起来overflow: auto 在 Firefox (v 22) 中被忽略了,但滚动条确实出现在 Chrome 中。

关于如何在内容部分需要时可靠地制作滚动条有什么想法吗?

【问题讨论】:

    标签: css dynamic web-applications scrollbar overflow


    【解决方案1】:

    您的关键问题是填充值,因此您需要在文章>部分中设置宽度减少一些百分比

    article>section {
        /* reduce diameter of rounded corner to match the inside curve of the border */
        border-radius: 10px;
        -moz-border-radius: 10px;
        display: block;
        overflow: auto;
        border: none;
        /*width: 100%;*/
        width: calc(100% - 30px) /* or set fixed width percentage like 90% */
        background-color: white;
        padding: 10px 10px 10px 20px;
        min-height: 50px;
        height: 100%;
    }
    

    【讨论】:

    • 您好,Calc 非常酷 - 不知道那个。我在 Chrome 中恢复了滚动条,但在 Firefox 中仍然没有运气。
    • 对于 chrom 使用 -webkit-calc(100% - 30px) 和对于 firefox 使用 -moz-calc() 但请注意至少 safari 6.0 有效。所以我的建议是使用固定宽度,比如 98%
    • 嗯,有些不太对劲。即使我以像素为单位设置了固定大小,它仍然没有得到滚动条。当我检查页面时,Firefox 在 Section 周围画了一个轮廓,它明显超出了文章的范围。但是 Firefox 仍然不显示滚动条。
    • 啊,我搞砸了。是最小值把事情搞砸了。它允许文章小于允许的最小值。
    【解决方案2】:
    article {
        position: absolute;
        min-width: 500px;   
        width: 918px;
        margin: 0px;
        padding: 0px;
        overflow: hidden; 
        background-color: white;
        border-style: ridge;
        border-color: #ddd;
        border-width: 4px;
        height:100px;
    }
    article>section {
        /* reduce diameter of rounded corner to match the inside curve of the border */
       overflow:auto;
       height:100%;
       border:none;
       display: block;
       padding: 10px 10px 10px 20px;
        min-height:50px;
    }
    

    【讨论】:

    • 感谢您的快速回复。但这并没有解决问题。进行建议的更改后,滚动条不再出现在 Chrome 中,也不会出现在 Firefox 中。
    猜你喜欢
    • 1970-01-01
    • 2013-12-25
    • 2018-07-22
    • 1970-01-01
    • 2014-01-21
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多