简体   繁体   English

显示带有背景大小的完整图像(高度):封面

[英]show full image (height) with background-size: cover

I'm writing an html page with parallax using stellar.js.我正在使用 stellar.js 编写一个带有视差的 html 页面。 In CSS I use:在 CSS 中,我使用:

html, body {height: 100%;}

#slide1 {
height: auto;
background-image:url('../images/1.jpg');
background-color:#fff;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed; }

But the image is cut and the bottom of the image is not visible.但是图像被剪切并且图像的底部不可见。

Is it possible to set the height of the section (#slide1) to show all the image?是否可以设置部分(#slide1)的高度以显示所有图像?

Using background-size:cover;使用background-size:cover; will always crop your background image either vertically or horizontally, except when the element has the exact same h/w ratio as the image.将始终垂直或水平裁剪您的背景图像,除非元素具有与图像完全相同的 h/w 比率。 The key is to choose and position the background in such manner that it still looks good when it is cut.关键是选择和定位背景,使其在剪切时仍然看起来不错。

Most likely, you want to give your element a min-height , eg:最有可能的是,你想给你的元素一个min-height ,例如:

#slide1 {
  min-height: 600px;
}

Keep in mind the most popular desktop ratio is 16:9 and most mobile devices are held vertically.请记住,最流行的桌面比例是 16:9,并且大多数移动设备都是垂直放置的。 If necessary, use @media queries for different device/viewport widths.如有必要,对不同的设备/视口宽度使用@media查询。

If you don't want your slide to have a larger height than the viewport height (deviceScreen|browser height), add max-height: 100vh!important;如果您不希望幻灯片的高度大于视口高度(deviceScreen|浏览器高度),请添加max-height: 100vh!important; to the above rule (useful on mobile devices).到上述规则(在移动设备上有用)。

尝试将 #slide1 height 属性设置为 100% 而不是使用 auto。

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

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