我试图更好地掌握HTML / CSS,而且我经常会看到类似的东西
background-size: 100px
当只有一个参数给出需要长度和宽度的东西时,它意味着什么?是否默认只根据图像定义长度和缩放宽度?或者它默认为宽度?
答案 0 :(得分:3)
如果只定义了一个尺寸,则将其作为宽度处理,并将高度自动设置为auto
。
来自the Mozilla Developer Network:
/* Keywords syntax */
background-size: cover
background-size: contain
/* One-value syntax: the value defines the width of the image, the height is implicitly set to 'auto' */
background-size: 50%
background-size: 3em
background-size: 12px
background-size: auto
/* Two-value syntax: the first value defines the width of the image, the second its height */
background-size: 50% auto
background-size: 3em 25%
background-size: auto 6px
background-size: auto auto
/* Values for the multiple backgrounds, defined by background-image, may be listed separated by commas */
background-size: auto, auto /* Do not confuse this with background-size: auto auto */
background-size: 50%, 25%, 25%
background-size: 6px, auto, contain
background-size: inherit