[英]Problem with vertical alignment of background image (background-position-y property)
I want to keep my background vertically-aligned (center) for all resolutions of screen.我想让我的背景在所有分辨率的屏幕上保持垂直对齐(居中)。 Always in the middle.总是在中间。 So i use background-position-y property as "center".所以我使用 background-position-y 属性作为“中心”。
Here is my css:这是我的 css:
body {
background: url('https://i.ibb.co/5npL7fr/shutterstock-2179562083-bg-1024x576-small.png');
background-repeat: no-repeat;
background-size: 100% auto;
background-position-y: center !important;
opacity: 1;
}
But i see that my background is vertically on the top, not in center.但我看到我的背景垂直在顶部,而不是在中心。 What is wrong?怎么了?
Here is jsfiddle - https://jsfiddle.net/opfbn72v/这是 jsfiddle - https://jsfiddle.net/opfbn72v/
If You want make it center try with this CSS Code:如果你想让它居中,试试这个 CSS 代码:
body {
background: url('https://i.ibb.co/5npL7fr/shutterstock-2179562083-bg-
1024x576-small.png');
background-repeat: no-repeat;
background-size: 100% auto;
background-attachment: fixed;
background-position: center;
opacity: 1;
}
And If you want to use background-position-y then you have to place the image inside the div tag and then you can use background-position-y center like:如果你想使用 background-position-y 那么你必须将图像放在 div 标签内然后你可以使用 background-position-y center 像:
div {
background: url('https://i.ibb.co/5npL7fr/shutterstock-2179562083-
bg-1024x576-small.png');
background-repeat: no-repeat;
background-size: 100% auto;
background-attachment: fixed;
background-position-y: center;
opacity: 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.