【问题标题】:Firefox box-sizing + expanding div = missing padding?Firefox box-sizing + 扩展 div = 缺少填充?
【发布时间】:2016-08-19 06:29:42
【问题描述】:

我一直在尝试使用box-sizing 和padding 来解决这个问题,其中我有一个扩展的 div(随着时间的推移添加内容)。上述案例在 ie 和 Chrome 上运行良好,但在 Firefox (33.0.2) 上表现异常。

这是链接

http://codepen.io/anon/pen/mydPdV

按住按钮。该按钮将通过以下方式将您带到页面末尾:

$("#button").click(function(){
    $("#container").scrollTop(99999999999999999);
});

页面填满并出现滚动后,您会看到由于 osme 原因 padding-bottom 将留在页面之外 - 仅在 firefox 上!在 Chrome 和 IE 上,它可以正常工作。

看起来 Firefox 在这里做了一些错误的计算?还是 int 根本不计算扩展/动态内容的填充?我错过了一点吗?

我正在寻找快速修复。

【问题讨论】:

  • 为什么正文是position: fixed;?
  • 此时重要吗?删除线不会改变任何东西。
  • 这只是......不寻常。
  • 对实际问题有什么想法吗?

标签: javascript jquery html css firefox


【解决方案1】:

$("#button").click(
  function(event){
    event.preventDefault();
    var newdiv = $("<div>");
    newdiv.text("Here is some dummy content");
    $('#content').append(newdiv);

    //$('#container').prop('scrollHeight');
    var sh = parseInt($("#content")[0].scrollHeight);
    //$('body,html').animate({scrollTop:sh},1000);
    $(window).scrollTop(sh);
    //return false
  }
);
body{
  text-align: center;
  margin: 0;
  background-color: lightgray;
  width: 100%;
  height:100%;
}
#container{
  background: lightpink none repeat scroll 0 0;
  margin:5%;
  width: 90%;
  -webkit-box-sizing: border-box;
	   -moz-box-sizing: border-box;
		    box-sizing: border-box;
}
#button{
  padding: 16px;
  background-color: white;
  cursor: pointer;
}
#content div {
  background-color: #eee;
  margin-bottom: 8px;
  padding: 16px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
  <div id="content"></div>
  <div id="button">PRESS ME</div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 2021-12-13
    • 2013-07-19
    • 2014-01-26
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多