gpt4 book ai didi

html - 如何让视差滚动占用屏幕的整个宽度和高度?

转载 作者:太空宇宙 更新时间:2023-11-04 08:33:24 24 4
gpt4 key购买 nike

如何让图像覆盖整个屏幕?

CSS:

.parallaxBg {
background-image: url("image_test.jpg");

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

HTML:

<div class="parallaxBg">
</div>

最佳答案

您需要将 body 高度设置为 100%:

body, html {
height: 100%;
padding: 0;
margin: 0;
}

parallaxBg 高度也为 100%:

height: 100%; 

例子:

body, html {
height: 100%;
padding: 0;
margin: 0;
}
#parallaxBg {
/* The image used */
background-image: url("https://placeimg.com/1000/800/any");

/* Full height */
height: 100%;

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

.text {
position: relative;
top: 600px;
height: 300px;
font-size: 2em;
background: blue;
padding: 2em;
}
<div id="parallaxBg">
<div class="text">
Bacon ipsum dolor amet corned beef doner pig filet mignon t-bone pancetta beef tongue ground round meatball pork belly landjaeger tail. Turducken flank pork t-bone, shoulder pastrami short loin drumstick jowl tail bresaola strip steak tenderloin frankfurter. Corned beef short loin chuck venison pork jerky. Jowl leberkas cupim turkey flank drumstick porchetta strip steak ham hock tail shoulder ball tip brisket tri-tip. Beef ribs bresaola short ribs cow tenderloin, jerky ball tip shankle pastrami shoulder t-bone.
</div>

希望这就是您所要求的!

关于html - 如何让视差滚动占用屏幕的整个宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44650949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com