我正在努力更好地掌握 HTML/CSS,而且我经常看到类似
背景大小:100px
对于需要长度和宽度的东西只给出一个参数是什么意思?它默认只根据图像定义长度和缩放宽度吗?还是默认为宽度?
最佳答案
如果只定义了一种尺寸,则将其作为宽度处理,高度自动设置为 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
关于html - CSS Background-size 一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23815151/