【问题标题】:Padding changing the size of a div with box-sizing on Firefox在 Firefox 上使用 box-sizing 填充更改 div 的大小
【发布时间】:2014-12-30 05:47:40
【问题描述】:

我正在尝试向 DIV 内的元素添加填充。我的问题是它将此填充添加到我的 DIV 的总大小中。

我尝试在我的 div 中使用以下代码来阻止这种情况:

box-sizing: border-box;
ms-box-sizing: border-box;
webkit-box-sizing: border-box;
moz-box-sizing: border-box;

它在 Chrome 上运行良好,但在 Firefox 上仍然存在问题。我不明白为什么。

有人知道如何解决这个问题吗?

非常感谢

【问题讨论】:

  • 请添加jsfiddle.net 或代码..
  • 您在 moz 和所有其他前缀之前缺少连字符,例如-moz-box-sizing: border-box;
  • 如果 Adrift 的评论没有解决问题,您使用的是什么版本的 firefox?
  • Adrift,非常感谢它运行良好!
  • 另外,IE 不需要 -ms- 前缀;它知道的唯一版本是普通的box-sizing。

标签: html css firefox width padding


【解决方案1】:

如果您想为 div 的宽度添加额外的填充:

div {
    // In this example total div width is 120px
    // box-sizing: content-box is the default style. No need to specify it.
    width: 100px
    padding: 0 10px;
}

或者如果你想让内边距成为 div 总宽度的一部分:

div { 
    // In this example total div width is 100px
    // support Firefox, WebKit, Opera and IE8+
    -moz-box-sizing: border-box;
    box-sizing: border-box; //always place the standard declaration last, so it overwrites browser specific ones in case they get deprecated  
    width: 100px
    padding: 0 10px;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-26
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    相关资源
    最近更新 更多