【发布时间】:2021-07-07 11:44:12
【问题描述】:
我在我的网站上使用 jumbotron 图像时遇到问题,随着屏幕尺寸的缩小和在移动设备上的极度放大,它们会越来越放大。这是jumbotrons的功能吗?我知道图像必须移动以填充屏幕,但除了极端情况外,我可以让它大部分固定吗?我使用 w3schools 的代码在 jumbotron 图像上创建视差效果,如果这与它有关的话。我的代码如下:
.jumbotron {
display: flex;
justify-content: center;
align-items: center;
background-image: url("./jumbo.jpg");
color: #ffffff;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding-top: 116px;
}
/* From w3schools - https://www.w3schools.com/howto/howto_css_parallax.asp */
.parallax {
/* The image used */
background-image: url("./jumbo.jpg");
/* Set a specific height */
min-height: 600px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: bottom;
background-repeat: no-repeat;
background-size: cover;
}
html中的用法示例:
<section class="jumbotron parallax image-overlay" style="background-image: url(./deadgrass.jpg);">
<div class="row justify-content-center">
<div class="col-auto text-center">
<h2>Contact Me</h2>
</div>
</div>
</section>
【问题讨论】:
标签: javascript html css image parallax