css - 背景:50% 50%/封面;这是什么意思?

标签 css background

.slide{
    background: 50% 50% / cover; 
}

背景:50% 50%/cover 的作用是什么?

我知道后台语法是这样的 http://www.w3schools.com/css/css_background.asp

body {
    background: #ffffff url("img_tree.png") no-repeat right top;
}

但是为什么我的代码中有 50% 50%/cover

最佳答案

A. 背景位置:50% 50%

background-position 具有以下值 position( left/right/center top/center/bottom) |x% y%|xpos ypos|initial|inherit;

background-position:50% 50% 表示

The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. . Default value is: 0% 0%

在这里阅读更多 background-position

B. 背景大小:封面

background-size 属性可以具有以下值background-size: auto|length|cover|contain|initial|inherit;

background-size:cover 这样做:

Scale the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area

看这里 background-size

所以在你的代码中:

body {
background: #ffffff url("img_tree.png") no-repeat right top;
}

右上角背景位置,因此50% 50%将位于其位置。 另外,您没有设置 background-size,因此它的值为 auto

如果你想组合这两个代码就这样写

body {
background: url("img_tree.png") no-repeat 50% 50% / cover #ffffff ;
}

翻译成

body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: cover;
background-color:#fff;
}

关于css - 背景:50% 50%/封面;这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38714276/

相关文章:

html - 是否可以使用 html 来设置我无法直接访问其代码的 div 的样式?

javascript - 无法让我的 Javascript 在 Joomla 中工作

android - Xamarin ContentPage BackgroundImage属性在Android上使应用程序崩溃

具有 getSize().width、getSize().height 的 Java 小程序

html - HTML 标签上的背景位置不起作用

css - 设置导航栏的背景图片 - bootstrap

javascript - 在 Action url php 中传递变量值

html - 如何让垂直线分隔 css 网格元素?

css - 打印时如何防止子div超出父div

java - 如何使渐变背景颜色更平滑