html - CSS Background-size 一个参数

标签 html css

我正在努力更好地掌握 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/

相关文章:

html - 如何使用:nth-child pseudo-class to change color of tiles on odd rows

javascript - 填充动画延迟

html - 在 jQuery UI 自动完成中使用 HTML

javascript - 强制元素永远不会失去对 HTML 的关注?

html - 背景颜色在 style.css 中不显示,但在 index.html 中显示

javascript - Webkit 转换不起作用,我该怎么办

javascript - 如何使用window.print()打印具有水平和垂直滚动条的DIV的全部内容?

jquery - 动画粘性导航?

javascript - HTML 中的通用 header

html - 图片之间的边距/空间不起作用