How does browsers compute 'auto' value?

房东的猫 提交于 2019-12-23 05:32:27

问题


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


回答1:


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




回答2:


I figured out the problem. Chrome renders it differently. Other browsers display it correctly. Only the Chrome browser in my PC displays it differently. The Chrome browser in my mobile displays it correctly so I guess it is a browser issue.



来源:https://stackoverflow.com/questions/20490903/how-does-browsers-compute-auto-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!