使用 CSS 将背景图像设为较高 div 的高度

发布于 2024-08-08 20:21:34 字数 172 浏览 1 评论 0原文

我的布局左侧是可变长度菜单,右侧是可变长度内容。菜单和内容之间是一个使用重复背景图像实现的分隔符,它是内容 div 的一部分。这意味着随着内容的扩展或收缩,分隔线也会扩展或收缩。

如果内容的高度小于菜单的高度,则分隔线仍然是内容的高度,而在这种情况下我真正想要的是分隔线是菜单的高度。有没有办法在CSS中实现这个?

I have a layout with a variable-length menu on the left, and variable-length content on the right. In between the menu and content is a divider implemented using a repeating background image, which is part of the content div. This means that as the content expands or contracts, so does the divider.

If the height of the content is less than the height of the menu, the divider is still the height of the content, when what I really want is the divider to be the height of the menu in this case. Is there any way to implement this in CSS?

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

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

发布评论

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

评论(2

苍白女子 2024-08-15 20:21:34

让内容和菜单中有分隔线背景图像,并使用负边距或类似的东西使内容区域与菜单重叠分隔线的宽度。

Have the dividers background image in the content are and the menu and have the content area overlap the menu the width of the divider using negative margins or something similar.

云巢 2024-08-15 20:21:34

另一种方法是在包装 div 上使用背景图像,并使用背景位置将其放置在菜单和内容 div 之间。

An alternative would be to use the background image on a wrapper div and use background-position to place it between the menu and content divs.

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