我检查了
MDN,看看有什么方法可以获得保证金属性的自动值,它说:“auto被替换为一些合适的值,例如它可以用于块的居中.”
但是什么是合适的价值,适合什么?
我尝试了一些实验,我看到如果我添加margin-left:auto,容器会向右移动(就像浮动到右边):
#container { background: red; width: 120px; margin-left: auto; }
这是否意味着添加保证金自动实际上就像“占用所有可用空间”?当你添加左右边距时,它会使div居中,因为它试图从左边和右边占据所有空间?
解决方法
Auto margins
Depending upon the circumstances,provision of an auto value instructs
the browser to render a margin according to the value provided in its
own stylesheet. However,when such a margin is applied to an element
with a meaningful width,an auto margin instead causes all of the
available space to be rendered as whitespace.
从w3.org起
原文地址:https://www.jb51.cc/html/231849.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。