\u0022.bgc{\n\tbackground: black;\n\tbackground-attachment: fixed;\n\tbackground-position: center;\n\tbackground-size: 100% 100%;\n}\n.bgc .bgc-photo{\n background: url("../../static/images/3bf0c157ecd41df7c23c39fc649ff3ef.png");\n background-attachment: fixed;\n background-position: center center;\n background-repeat: no-repeat;\n background-size: 100% 100%;\n display: flex;\n height: 35rem;\n width: 80rem;\n}\n怎么让背景图片在背景颜色里占80%,并且垂直水平居中内容:您可以使用flex布局来实现背景图片在背景颜色里占80%并且垂直水平居中。下面是一个示例代码:\n\ncss\n.bgc {\n background: black;\n background-attachment: fixed;\n background-position: center;\n background-size: 100% 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.bgc .bgc-photo {\n background: url(\"../../static/images/3bf0c157ecd41df7c23c39fc649ff3ef.png\");\n background-attachment: fixed;\n background-position: center center;\n background-repeat: no-repeat;\n background-size: 80% auto;\n height: 35rem;\n width: 80rem;\n}\n\n\n在上面的代码中,我们在父元素.bgc上使用了flex布局,并分别使用justify-content: center;align-items: center;来使背景图片垂直水平居中。同时,我们将背景图片的background-size设置为80% auto来使其占父元素宽度的80%。\n\n请根据您的实际情况调整.bgc .bgc-photo的宽度和高度,以及背景图片的路径。

CSS实现背景图片在背景颜色里占80%并垂直水平居中

原文地址: https://www.cveoy.top/t/topic/p6MQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录