浏览器如何计算“自动”值? [英] How does browsers compute 'auto' value?
问题描述
我有两种相似的风格。当我在铬检查器中查看它们时,它们具有不同的值,尽管所用的样式类似。
元素的边距具有自动值,但当浏览器计算出来时,它们之间的差异虽然宽度是相同的。
对于那些会要求我将它指向单个样式表的人,实际上我不能这样做,因为第一种样式是一个wordpress主题,另一个是一个whmcs模板。
更新:
新增了这两个截图。两个窗口都被最大化了
当您设置 auto
左右边距都会使元素居中。如果您仅为左边距设置 auto
,则该元素将与右侧对齐。
阅读更多< a href =https://developer.mozilla.org/en-US/docs/Web/CSS/margin#Values =nofollow> https://developer.mozilla.org/zh-CN/docs/ Web / CSS / margin#值
I have two similar styles. When I viewed them in the chrome inspector they have different values although the styles applied are similar.
The margins of the elements have the 'auto' value but when computed by the browser there is a big difference between them although the width is the same.
For those who will be asking me to point it to a single stylesheet, I actually can't because the first style is for a wordpress theme and the other one is for a whmcs template.
Update:
added these two screenshots. both windows are maximized
auto
is not a specific value, and on a block element basically means to let the browser decide. (As in, take up remaining space). I expect your browser window width, or a parent element is wider in the case where you see the larger margin being rendered. (See the "styles" tab instead of the "computed" to see the applied styles)
When you set auto
for both left and right margin, it will center the element. If you set auto
only for left margin, the element will align to the right side.
Read more at https://developer.mozilla.org/en-US/docs/Web/CSS/margin#Values
这篇关于浏览器如何计算“自动”值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!