简体   繁体   English

调整水平滚动div到内容

[英]Adjust horizontal scrolling div to content

I'm developing a web with horizontal scrolling sections.我正在开发一个带有水平滚动部分的网络。 For that I have used only CSS.为此,我只使用了 CSS。 My code rotates the container to make the horizontal scrolling the 'natural' one.我的代码旋转容器以使水平滚动成为“自然”滚动。 What I would like is to adjust the width of the container to the images it contains, so it doesn't allow you to scroll further than the images.我想要的是将容器的宽度调整为它包含的图像,因此它不允许您滚动得比图像更远。 Here's my html and css code这是我的 html 和 css 代码

 .slide { height: 80vh; background-size: auto 100vh; background-repeat: repeat-x; width: 2000vw; } .wrapper { display: flex; flex-direction: row; width: 2000vw; transform: rotate(90deg) translateY(-80vh); transform-origin: top left; } .outer-wrapper { width: 80vh; height: 100vw; transform: rotate(-90deg) translateX(-80vh); transform-origin: top left; overflow-y: scroll; overflow-x: hidden; position: absolute; scrollbar-width: none; -ms-overflow-style: none; }
 <div *ngIf="ready" class="container-fluid" id="projects"> <div class="outer-wrapper"> <div class="wrapper"> <div class="slide one"> <img *ngFor="let image of images" class="img-fluid" [src]="image"> </div> </div> </div> </div>

I have tried changing a lot of combinations of the css but none of them will work for more than one fixed screen size我曾尝试更改 css 的许多组合,但没有一个可以用于多个固定屏幕尺寸

Which one is closer?哪个更近?

In the first one I removed your "slide one" div and used the img tags directly inside the wrapper.在第一个中,我删除了您的“幻灯片”div 并直接在包装器内使用了 img 标签。 Also, removed the width setting from .wrapper class.此外,从 .wrapper 类中删除了宽度设置。

In the second one, I used divs and background images.在第二个中,我使用了 div 和背景图像。 They're now huge, covering the screen, and for this to happen, a few things needed to change in the .slide class.它们现在很大,覆盖了屏幕,要实现这一点,需要在 .slide 类中更改一些内容。

If this is what you wanted to achieve, I'm going to pimp this post a bit so others see what's going on.如果这就是你想要实现的目标,我将把这篇文章稍微拉一下,让其他人看看发生了什么。 But I guess it has the desired effect.但我想它有预期的效果。 If not, let's work on it.如果没有,让我们继续努力。

(Picture samples are from instagram.com and the original owner is Vola Udabe Randri, aka olaizolav - in case you were wondering) (图片样本来自 instagram.com,原主人是 Vola Udabe Randri,又名olaizolav - 如果你想知道的话)

Finally I managed to solve this issue myself.最后我自己设法解决了这个问题。 The key is using vh (viewport height) units to specify the width of the wrapper, so the proportions will always be conserved.关键是使用 vh(视口高度)单位来指定包装器的宽度,因此比例将始终保持不变。

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

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