简体   繁体   English

如何使我的图像背景以任何尺寸响应

[英]How to make my image background responsive in any size

Hello guys can anyone help me with this, When I tried viewing my design on a smaller screen the image background is not look alike on the big screen can anyone help me how to achieve it?大家好,任何人都可以帮我解决这个问题,当我尝试在小屏幕上查看我的设计时,图像背景在大屏幕上看起来不一样,谁能帮我实现它? the first image is the background I've been using.第一张图片是我一直在使用的背景。

 .container-flex.lgn-customize { position: relative; width: 100%; background-color: #fff; min-height: 100vh; overflow: hidden; /* background-image: url(/materials/media/icons/login-icon/login_bg.png); */ background-position: bottom center; background-repeat: no-repeat; background-size: cover; }.nk.container-flex { width: 100%; max-width: initial; margin-left: auto; margin-right: auto; }.container-flex.lgn-customize::before { content: ""; position: absolute; height: 100%; width: 100%; top: 49%; transform: translate(100%, -50%); right: 0%; transform: translateY(-50%); background-image: url(/materials/media/icons/login-icon/test222111.png); /* background-position: bottom center; */ background-repeat: no-repeat; background-size: cover; /* transition: 1s ease-in-out; */ /* border-radius: 50%; */ z-index: 6; }
 <div class="container-flex lgn-customize"> </div>

我在 css 中使用的实际图像

大屏幕

小屏幕

Try setting the background-size property to contain.尝试将 background-size 属性设置为包含。 It tells the browser that the background image scales trying to fit the content area, without loosing its aspect ratio.它告诉浏览器背景图像缩放以适应内容区域,而不会丢失其纵横比。

 <style>.container-flex.lgn-customize { position: relative; width: 100%; background-color: #fff; min-height: 100vh; overflow: hidden; background-image: url('https://images.unsplash.com/photo-1604085572504-a392ddf0d86a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8b3JhbmdlJTIwZmxvd2VyfGVufDB8fDB8fA%3D%3D&w=1000&q=80'); background-position: bottom center; background-repeat: no-repeat; background-size:contain; }.nk.container-flex { width: 100%; max-width: initial; margin-left: auto; margin-right: auto; }.container-flex.lgn-customize::before { content: ""; position: absolute; height: 100%; width: 100%; top: 49%; transform: translate(100%, -50%); right: 0%; transform: translateY(-50%); background-image: url(/materials/media/icons/login-icon/test222111.png); /* background-position: bottom center; */ background-repeat: no-repeat; background-size: cover; /* transition: 1s ease-in-out; */ /* border-radius: 50%; */ z-index: 6; } </style> <div class="container-flex lgn-customize"> </div>

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

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