浏览器如何计算“自动”值? [英] How does browsers compute 'auto' value?

查看:171
本文介绍了浏览器如何计算“自动”值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种相似的风格。当我在铬检查器中查看它们时,它们具有不同的值,尽管所用的样式类似。


元素的边距具有自动值,但当浏览器计算出来时,它们之间的差异虽然宽度是相同的。



对于那些会要求我将它指向单个样式表的人,实际上我不能这样做,因为第一种样式是一个wordpress主题,另一个是一个whmcs模板。



更新:



新增了这两个截图。两个窗口都被最大化了



解决方案

auto 并不是一个特定的值,在块元素上基本上意味着让浏览器决定。 (如在,占用剩余空间)。我期望浏览器窗口宽度,或者在显示更大页边空白的情况下,父元素更宽。 (请参阅样式选项卡,而不是计算以查看应用样式)



当您设置 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆