盒模型的问题_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了盒模型的问题_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2597字,纯文字阅读大概需要4分钟。
内容图文
![盒模型的问题_html/css_WEB-ITnose](/upload/InfoBanner/zyjiaocheng/402/f9ca3c1d995b4cf1ae352ddb8613c6e7.jpg)
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
回复讨论(解决方案)
box-sizing 设为 content-box 时, height 和 width 只包含内容, 不含 padding 和 border
设为 border-box 时, height 和 width 包含 padding 和 border
你看看 W3C 官方的文档:
http://www.w3.org/TR/css3-ui/#box-sizing
content-box
This is the behavior of width and height as specified by CSS2.1. The specified width and height (and respective min/max properties) apply to the width and height respectively of the content box of the element. The padding and border of the element are laid out and drawn outside the specified width and height.
border-box
Length and percentages values for width and height (and respective min/max properties) on this element determine the border box of the element. That is, any padding or border specified on the element is laid out and drawn inside this specified width and height. The content width and height are calculated by subtracting the border and padding widths of the respective sides from the specified width and height properties. As the content width and height cannot be negative ([CSS21], section 10.2), this computation is floored at 0. Used values, as exposed for instance through getComputedStyle(), also refer to the border box.
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
如果我想要明确的设置内容的 height 和 width, 但 css 的 height 和 width 这两个属性却始终把 padding 和 border 的尺寸都包含在其中, 那我设置时不就是得先计算才能设置好吗
比如
$(element).css('width', 内容期望的宽度 + padding-left + padding-right + border-left + border-right);
这样岂不是相当麻烦吗, 而且如果 padding-left , padding-right , border-left, border-right 之中的任意一个发生改变时, 都将影响到 内容的宽度
还有我想问为什么CSS默认外边距,内边距和框的值要独立出来,不算在盒的高度和宽度里面?这样有什么好处吗?
如果我想要明确的设置内容的 height 和 width, 但 css 的 height 和 width 这两个属性却始终把 padding 和 border 的尺寸都包含在其中, 那我设置时不就是得先计算才能设置好吗
比如
$(element).css('width', 内容期望的宽度 + padding-left + padding-right + border-left + border-right);
这样岂不是相当麻烦吗, 而且如果 padding-left , padding-right , border-left, border-right 之中的任意一个发生改变时, 都将影响到 内容的宽度
非常感谢。
内容总结
以上是互联网集市为您收集整理的盒模型的问题_html/css_WEB-ITnose全部内容,希望文章能够帮你解决盒模型的问题_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。