[英]Background scrolls while content is fixed
I am making a website using vue.js and Bootstrap I have made use of bootstrap's jumbotron
component at the top of my web page right below my navigation and I would like to know how to make some of the elements scrollable while keeping some elements stationary.我正在使用 vue.js 和 Bootstrap 创建一个网站,我在导航下方的 web 页面顶部使用了 bootstrap 的
jumbotron
组件,我想知道如何使一些元素可滚动,同时保持一些元素静止。 I will include an example as I am aware this is still confusing at this point.我将举一个例子,因为我知道这在这一点上仍然令人困惑。
Demo演示
This is a demo of just the jumbotron there will be other content on the page beside the jumbotron what I want is the Buick logo (I will have other logos as well) to scroll for a short time in the background behind the other content until the main scroll action of the page takes over. 这是jumbotron的演示,在jumbotron旁边的页面上会有其他内容我想要的是别克标志(我也会有其他标志)在其他内容后面的背景中滚动一小段时间,直到页面的主要滚动动作接管。 I hope what I am looking for is clear now.
我希望我现在正在寻找什么是清楚的。 If you need more info I will be happy to provide it.
如果您需要更多信息,我将很乐意提供。
Just to be clear in these pictures just show the jumbotron not the whole page.只是为了清楚地在这些图片中显示 jumbotron 而不是整个页面。 Also fixed position is not a solution to my problem as I want the stationary elements to remain in the jumbotron.
还修复了 position 不是我的问题的解决方案,因为我希望固定元素保留在 jumbotron 中。
If I get the problem right, this should do the trick: https://codesandbox.io/embed/serene-rhodes-42224?fontsize=14&hidenavigation=1&theme=dark .如果我的问题正确,这应该可以解决问题: https://codesandbox.io/embed/serene-rhodes-42224?fontsize=14&hidenavigation=1&theme=dark 。
Briefly what was done:简要说明做了什么:
So from what I understand you want to make some elements scrollable whilst others are in fixed positions.因此,据我了解,您希望使某些元素可滚动,而其他元素则处于固定位置。 this can be done using css positioning and overflow.
这可以使用 css 定位和溢出来完成。 If you have an element that you want to be unscrollable unless there is enough content in that div to make it scrollable use the following css
如果您有一个想要不可滚动的元素,除非该 div 中有足够的内容使其可滚动,否则请使用以下 css
position: fixed; overflow-y:scroll;
However if you want the element to remain unscrollable (you cant scroll on it no matter what) just use the following css:但是,如果您希望元素保持不可滚动(无论如何都无法滚动),只需使用以下 css:
overflow: hidden;
You need to use background-attachment
property of CSS.您需要使用 CSS 的
background-attachment
属性。
HTML: HTML:
<div class="fixed">
--- Your Content Here ---
</div>
CSS: CSS:
.fixed {
background: url('https://cdn.pixabay.com/photo/2016/06/11/23/22/soap-bubbles-1451092_960_720.jpg');
background-attachment: fixed;
height: 400px;
width: 50%;
max-width: 600px;
margin: 32px auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.