We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
要实现上述右对齐的方式有很多,比如:
前面三个方法的都好理解,第四个方法相信会让不少人困惑,但它确确实实可以实现,示例如下:
<html> <head> <style> .right { margin-left: auto; width: 100px; height: 50px; background-color: #f00; } .box { width: 400px; border: 1px solid #000 } </style> </head> <body> <div class="box"> <div class="right"></div> </div> </body> </html>
要实现上述水平居中的方式有很多,其中有一种方式就是在固定宽度时,使用margin: 0 auto可以实现水平居中,想必使用这个方法的时候也会困扰一会。
margin: 0 auto
<html> <head> <style> .middle { margin: 0 auto; width: 100px; height: 50px; background-color: #0f0; } .box { width: 400px; border: 1px solid #000 } </style> </head> <body> <div class="box"> <div class="middle"></div> </div> </body> </html>
块级元素中auto属性的计算特性
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
margin-left
margin-right
auto
The text was updated successfully, but these errors were encountered:
No branches or pull requests
一、margin-left: auto;元素右对齐
要实现上述右对齐的方式有很多,比如:
前面三个方法的都好理解,第四个方法相信会让不少人困惑,但它确确实实可以实现,示例如下:
二、margin: 0 auto;水平居中
要实现上述水平居中的方式有很多,其中有一种方式就是在固定宽度时,使用
margin: 0 auto
可以实现水平居中,想必使用这个方法的时候也会困扰一会。三、原理
块级元素中auto属性的计算特性
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
,除width以外,等号左侧属性的默认值为0。margin-left
和margin-right
都为auto
时,两者就会一样,从而使元素居中参考文献
The text was updated successfully, but these errors were encountered: