'overflow-y:auto' 的 CSS 问题在 Chrome 中产生了问题,但在 Firefox 中没有

标签 css firefox google-chrome browser cross-browser

在我的应用程序中,文本由用户输入并显示在具有固定宽度和高度以及 overflow-y:auto 属性的 div 中。 html 看起来像这样:

<div class="description_div scroll-pane jspScrollable" style="overflow-x: hidden; overflow-y: hidden; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; width: 290px; " tabindex="0">
    <div class="jspContainer" style="width: 290px; height: 160px; ">
        <div class="jspPane" style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 280px; left: 0px; ">
           <p>This is an original song written and performed by me, Jessica Speziale. I wrote this in early May 2011 :) Let me know what you think!</p>
           <p>Studio is 3 DAYS AWAY!!!  *dies*  I’ll be sending daily studio blogs via my newsletter!  Also, if you sign-up for the newsletter before August 31st, you’ll be entered to win a free copy of my EP!  Woot!! </p>
           <p>Sign up here: http://www.reverbnation.com/page_object/join_mailing_list/artist_868563</p>
        </div>
    </div>
</div>

外层 div 是我指定的,所有其他 div 都是使用 jscrollpane plugin 动态生成的.这是外部 div 的 css:

.description_div{
    float:right;
    width:280px;
    height:160px;
    overflow-y:auto;
    padding:5px;
    margin-left:5px;
}

问题是这在 Firefox 中正确呈现,但在 Chrome 中不正确。这是它在 Firefox 中如何呈现的图片:

Firefox-1 Firefox-2

这是它在 Chrome 中的呈现方式:

Chrome-1 Chrome-2

如您所见,在 Firefox 中,它剪切了 div 底部的长 url,以便所有文本都适合 div 的宽度,并添加了一个垂直滚动条。

在Chrome中,它把底部的最后一段文字截掉,只增加了一个水平滚动条。

这是为什么,有解决办法吗?

最佳答案

Firefox 中的默认换行算法可以在正斜杠处插入换行符,而 Chrome 中则不能。但是,您可以将 word-wrap: break-word; 样式添加到外部 div 以强制换行。确保 padding-right 未设置为 0(从您的代码示例中不清楚当前是否设置为 0),否则由于滚动条,某些文本将不可见。

关于 'overflow-y:auto' 的 CSS 问题在 Chrome 中产生了问题,但在 Firefox 中没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116682/

相关文章:

session - 如何恢复 Firefox 不是最后的 "Restore Previous Session"页面

html - HTML 中的固定位置 div 位于辅助 div 的背景图像前面

html - 在 HTML 的 div 框中定位图像

javascript - 如何从 Firefox 的 webextension 中读取本地文件?

javascript - 在调试控制台代码上设置断点

Javascript:Date() 函数在 Google Chrome 中无法完全运行

javascript - 打包 Chrome 应用程序 - 自动 Google 登录?

css - React 应用程序 - 避免样式被其他 CSS 覆盖

javascript - 如何堆叠来自两个不同元素的按键事件和点击事件来触发相同的功能

python - Python中的Selenium下载文件: even after setting Firefox Profile the Download Window opens