【发布时间】:2015-08-22 14:53:00
【问题描述】:
我正在关注这篇文章https://css-tricks.com/almanac/properties/w/width/ 以尝试了解此规则的工作原理。
我有这个例子:
*{margin:0; padding:0}
.box{
background: lightgreen;
margin: 0 auto;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
}
<div class="box">
<img src="https://tyrannyoftradition.files.wordpress.com/2012/05/cutest-kitten-hat-ever-13727-1238540322-17.jpg" alt="" />
<figure>Yes, put some text here that is wider than the image above to try some new rules</figure>
</div>
文章说fit-content可以用来将未知宽度的div与margin: x auto;居中
但是,如果您在此示例中将 fit-content 更改为 max-content,无论如何这仍然有效,并且它们的行为似乎始终相同。
有谁知道这两条规则有什么区别,在什么情况下我应该使用其中一个?
【问题讨论】:
-
虽然caniuse.com/#feat=intrinsic-width 还没有得到很好的支持