How to make background image fit correctly inside a board without losing responsiveness

前端 未结 3 935
旧巷少年郎
旧巷少年郎 2021-01-06 20:36

I have code in which there is class box, i have given backgroundimage to class box box1.

my problem is that the im

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 20:45

    I suggest you give your body a background-position according to your requirements. usually centering it is the best choice:

    background-position: center center;
    

    You can see how it works by looking at the snippet. resize the image by its bottom-right handle.

    div{
    	background-image: url('//unsplash.it/500');
    	background-size:cover;
    	background-position:center;
    	resize:both;
    	overflow:auto;
    	width:100%;
    	height:200px;
    }

提交回复
热议问题