高级 CSS 布局 |带超大图片的固定柱

发布于 2024-11-02 20:07:39 字数 328 浏览 3 评论 0原文

好吧,今晚我的大脑可能不工作了。我想要完成的是两列布局,其中一列滚动,另一列固定。固定列中有一个非常大的背景图像,我希望能够缩放到屏幕的大小。此外,左(固定)列的宽度必须缩放以适应背景图像。真正解释这一点的最好方法是用一张图片: 布局 带有箭头的突出显示区域将滚动,其中包含图片和 Twitter 状态的另一列将保持固定。我的问题与固定的 CSS 定位无关。我的问题是根据屏幕尺寸缩放列,以便图片始终保持此处显示的比例,无论是其自身尺寸还是其他列的尺寸。这就是我所坚持的。有什么想法吗?我真的很感谢你的帮助。

OK so my brain is just probably not working tonight. What I'm trying to accomplish is a two column layout where one column scrolls and the other is fixed. The fixed column has a very large background image in it that I would like to be able to scale to the size of the screen. Additionally the left (fixed) column's width would have to scale to accommodate the background image. The best way to really explain this is with a picture:
Layout
The highlighted area with the arrow in it will scroll and the other column with the picture and twitter status in it would remain fixed. My problem does not come into play with the fixed CSS positioning. My issue is with scaling my columns based on screen size so that the picture always remains in the proportion it's shown here both in it's own dimensions and those of the other column. That's what I'm stuck on. Any ideas? I really appreciate the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心房的律动 2024-11-09 20:07:39

我认为您可以在第一列中使用图像元素并将其设置为 100% 的父元素。如果父 div 也是百分比,那么它的大小当然会改变,并且也会缩放其中的图像。如果我们希望图像缩放,那么我们就不能同时指定高度。

<div id="parent" style="width: 40%">
  <img id="child" style="width: 100%" src="https://i.sstatic.net/lvvrv.png" alt="Fake Background" />
</div>

I think you can just use an image element in your first column and set it to take 100% of its parent. If the parent div is also a percentage then its size will change of course and that also scales the image within. If we want the image to scale, then we can't also specify a height.

<div id="parent" style="width: 40%">
  <img id="child" style="width: 100%" src="https://i.sstatic.net/lvvrv.png" alt="Fake Background" />
</div>
兮子 2024-11-09 20:07:39

在此处检查您的 JS FIDDLE 代码: http://jsfiddle.net/4P9fJ/7/

因为您 din更不用说您会更改背景中的图像,我在正文标记中提供了背景图像。

Check your JS FIDDLE CODE HERE : http://jsfiddle.net/4P9fJ/7/

Since you din't mention you'd be changing the images in your background i provided the background image in the body tag .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文