将 div 高度与灵活图像的高度匹配

发布于 2024-12-19 08:16:54 字数 297 浏览 3 评论 0原文

目前我只使用 HTML 和 LESS CSS...

我已将 img 标签设置为 max-width: 100%,这样,本质上,我的图像都是灵活的,并且尺寸完美地适合在其中/上查看它们的窗口/屏幕。

包含图像的是 div,其宽度始终 100%,但是其高度需要与图像的高度匹配。

如何使 div 与(灵活)图像具有相同的高度?有没有什么方法可以只使用 HTML 和 LESS CSS 来做到这一点,还是需要 Javascript?

任何帮助将不胜感激,谢谢:)

Currently I'm using just HTML and LESS CSS...

I've set my img tag to have a max-width: 100% so that, essentially, my images are all flexible and sized perfectly to the window/screen that they are viewed in/on.

Containing the images are divs, whose widths are always 100%, but, whose heights need to match that of the images.

How can I get the divs the same height as the (flexible) images? Is there any way to do this just with HTML and LESS CSS or is Javascript required?

Any help would be appreciated, thanks :)

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

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

发布评论

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

评论(2

眼泪淡了忧伤 2024-12-26 08:16:54

是的,您可以为此使用clearfix...

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}

将“.clearfix”添加到包含img的div中。

yes you can use a clearfix for this...

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}

add ".clearfix" to your div containing the img.

杀お生予夺 2024-12-26 08:16:54

尝试以下 css:

overflow:auto;

在图像所在的所有 div

try the following css:

overflow:auto;

on all of the divs that the image is in.

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