将 div 高度与灵活图像的高度匹配
目前我只使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以为此使用clearfix...
将“.clearfix”添加到包含img的div中。
yes you can use a clearfix for this...
add ".clearfix" to your div containing the img.
尝试以下 css:
overflow:auto;
。在图像所在的所有
div
上try the following css:
overflow:auto;
on all of the
div
s that the image is in.