简体   繁体   English

如何设置背景图片的高度

[英]how to set the height of background image

I have an image.I wish to set it as background image.I want to it to cover the entire size so i used background-size:cover;我有一个图像。我希望将其设置为背景图像。我希望它覆盖整个尺寸,所以我使用了background-size:cover; .It covers the entire length but the image is clipped at the bottom.Can anyone help me to set the background-size:cover; 。它覆盖了整个长度,但图像在底部被剪掉了。谁能帮我设置背景大小:封面; also the image to its full length and height?图像的全长和高度?

Css have min height .. you can use it when your background size is cover... Css 有最小高度.. 当你的背景尺寸被覆盖时你可以使用它......

Css: css:

.bg{
    background: url('path/to/image.png');
    background-size: cover;
    min-height: 500px;
}

Html :网址:

<div class="bg"> </div>

you can use the vh CSS values (relative to viewport height): this will set the height to 1/10th of the height of the viewport:您可以使用 vh CSS 值(相对于视口高度):这会将高度设置为视口高度的 1/10:

    background-image:url('*YOUR URL HERE*');
    background-repeat:no-repeat;
    background-size:contain;
    min-height:10vh;

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

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