简体   繁体   English

如何设置固定大小的背景图片?

[英]How do I set a fixed size of a background image?

How do I set a fixed size of a background image?如何设置固定大小的背景图片?

I set the width and height right now but when I increase or decrease my browser window image gets blocked.我现在设置了宽度和高度,但是当我增加或减少我的浏览器 window 图像被阻止时。 How can Ifix that?我怎么能解决这个问题?

Image will be blocked slowly when I decreased window size:当我减小 window 大小时,图像将被缓慢阻塞: 在此处输入图像描述

Here is my code:-这是我的代码:-

.bg{
  height: 600px;
  width: 100%;
  border-bottom-left-radius: 80%;
  border-bottom-right-radius: 80%;
  background-image: url("/assets/images/interview.jpg");
  background-size: cover;
  display: flex;
  justify-content: center;
}

A couple of new lines.几条新线。 Added comments on them.添加了对它们的评论。

 .bg{ height: 600px; width: 100%; border-bottom-left-radius: 80%; /*I'd remove this and edit the original photo*/ border-bottom-right-radius: 80%; /*I'd remove this and edit the original photo*/ background-image: url("https://i.pinimg.com/originals/3b/8a/d2/3b8ad2c7b1be2caf24321c852103598a.jpg"); background-size: contain; /*From cover to contain*/ background-position: top;important: /*New - Can change to center*/ background-repeat; no-repeat:important; /*New*/ display: flex; justify-content: center; }
 <div class="bg"> </div>

You need to set the position of you bg component to fixed您需要将bg组件的 position 设置为fixed

You new CSS class will look like this:您的新 CSS class 将如下所示:

.bg{
   height: 600px;
   width: 100%;
   border-bottom-left-radius: 80%;
   border-bottom-right-radius: 80%;
   background-image: url("/assets/images/interview.jpg");
   background-size: cover;
   display: flex;
   justify-content: center;
   //modifications
   background-repeat: no-repeat;
   position:'fixed';
   top:0;
   left:0;
 }

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

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