css background-image - 不要改变第一张图片的大小

标签 css

我需要将 2 张图片制作成相同尺寸,所以我不想更改第 1 张图片的大小。

到目前为止我有这个

background-image: url("1.png"), url("2.jpg");
background-position: 3% 10%, 83% 27%;
background-size:[I dont want this to have values basically], 83% 27%;   
background-repeat: no-repeat, no-repeat;
position: relative;

我也曾尝试将 bg-size 的第一个值留空,但从未奏效。

提前致谢。

最佳答案

尝试使用:

background-size:auto, 83% 27%;

From MDN:

The auto keyword that scales the background image in the corresponding direction such that its intrinsic proportion is maintained.

If the background-size is auto or auto auto: If the image has both intrinsic dimensions, it is rendered at that size. If it has no intrinsic dimensions and no intrinsic proportion, it is rendered at the size of the background positioning area. If it has no dimensions but has a proportion, it's rendered as if contain had been specified instead. If the image has one intrinsic dimension and a proportion, it's rendered at the size determined by that one dimension and the proportion. If the image has one intrinsic dimension but no proportion, it's rendered using the intrinsic dimension and the corresponding dimension of the background positioning area.

关于css background-image - 不要改变第一张图片的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24820321/

相关文章:

css - map Canvas 大小 MapboxGL JS

javascript - IE11/Edge 的 "styleWithCSS"有任何替代品吗?

php - 从备用目录解析 CSS 链接

html - Bootstrap 3 - 标题在浏览器中有神奇的空白

php - 使用 PHP 缩小 CSS 文件

php - Wordpress 内容框格式不正确

css - Aikau 和 css 要求

html - OpenLayers 3 - MousePosition 悬停问题

html - 为什么我的表格在我的导航栏之后不在新行开始?

html - :last-child:before with column-count behaving differently in chrome and firefox