内层图片元素高度自适应,外层盒子高度如何保持跟图片高度一致?

在开发的过程中,外层盒子高度不确定的情况下,想要跟内层图片高度保持一致,内层图片高度设为width:100%;height:auto;外层box高度也是width:100%;height:auto.为什么会比图片本身到高度超出去一部分呢?
外层box如何可以跟内层不确定高度的图片高度保持一致呢?

复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>height auto</title>
        <style>
            .container {
                width: 100%;
                height: auto;
                background-color: aquamarine;
            }
            img {
                width: 300px;
                height: auto;
                /* 主要通过这一行来实现 */
                vertical-align: bottom;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <img src="./猫咪咪.jpg" alt="" />
        </div>
    </body>
</html>
复制代码

来源

posted @   蓓蕾心晴  阅读(158)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示