gpt4 book ai didi

HTML div 宽度适合图像

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:13 24 4
gpt4 key购买 nike

<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
width: auto;
}
</style>
</head>
<body>

<div>
<img src = "http://www.flowerpicturegallery.com/d/1977-3/yellow+daisy+flower+picture.jpg">
</div>

</body>
</html>

我使用上面的代码来显示图像。除了两个事实,代码运行良好:1) 如何使 div 的宽度适合图像(在图像停止的地方停止)?我尝试了 width: auto;width: 100%; 但它们都不起作用......并且 2) 为什么底部有一个非常小的空白区域以及如何我可以解决这个问题吗?

最佳答案

HTML

<div class="child-width">
<img src = "http://www.flowerpicturegallery.com/d/1977-3/yellow+daisy+flower+picture.jpg">
</div>

CSS

.child-width {
border: 1px solid black;
display: inline-block; // add this
}

检查这个example fiddle

关于HTML div 宽度适合图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44325691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com