繁体   English   中英

如何将我的':after'背景图像居中?

[英]How to center my ':after' background-image?

我有一个背景图像,涵盖浏览器的整个宽度和高度。 在较小的屏幕上打开html文件时,只能看到图像的左侧。

我想要的是在背景上缩放和居中图像。 我的css代码有什么变化?

div#background-content {
    position: relative;
}

div#background-content:after {
    background-image:url('./images/sunrise.jpg');
    opacity:0.7;
    width: 100%;
    height: 100%;
    background-size:cover;
    display:block;
    content : "";
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
}

你可以在你的CSS中添加这段代码:

 div#background-content:after {
    background-size:contain;
    background-position:center;
    }

CSS 背景位置

background-position: center;

添加背景位置:中心; 我推荐你使用background:url('./images/sunrise.jpg') no-repeat center;

div#background-content:after{
   background-position: 50% 50%;
   background-size: cover;
   background-repeat: no-repeat;
}
div#background-content:after {
background-image:url('./images/sunrise.jpg');
opacity:0.7;
width: 100%;
height: 100%;
background-position: left -206px top -95px !important;
background-size: 320% 110% !important;
display:block;
content : "";
position: absolute;
top: 0;
left: 0;
z-index: -1;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM