对图像使用 max-width
而不是 width
可以避免对图像进行上采样,但为什么这在使用时会有所不同:
max-width: 800px;
margin: 0 auto;
最佳答案
如果你想在你的容器的中心显示你需要display:block
,所以代码应该是:
max-width: 800px;
display: block;
margin: 0 auto;
max-width
用于填充所需的宽度。
关于css - 为什么在使用 margin auto 居中元素时 max-width 的行为与 width 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46519537/