html - 将 html 图形宽度设置为其包含的图像宽度相同

标签 html css image

当图形标签内有图像时,图形宽度为 100%。如何使图形始终与图像具有相同的宽度?这是我当前的代码:

HTML:

<figure>
    <img src="http://www.google.com/images/srpr/logo3w.png" alt="" />
</figure>

CSS:

* {
    margin: 0;
    padding: 0;
}

figure {
    border: 1px solid red;
}

img {
    border: 1px solid blue;
    vertical-align: top;
}

最佳答案

像这样将display:table添加到figure css

figure 
{
    display:table;
    border: 1px solid red;
}

JS Fiddle Demo

关于html - 将 html 图形宽度设置为其包含的图像宽度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15557769/

相关文章:

html - 无法获取 2 张图像以展开以填充父 div

jquery - 动画div到li元素jquery

css - react 应用程序 : How To Create A Black Overlay For A Picture?

html - 以 html 格式显示的产品说明

php - echo 图像位置确实适用于带有空格的图像名称

c++ - 如何用 EXIF 数据写入图像 (Matlab/C++)

html - 如何像 Lynx 那样使用 Perl 将 HTML 呈现为文本?

javascript - 如何在 HTML 页面解析后将行号放在源代码中?

html - 使用 steps() 函数的 CSS Image Sprite Animations 不适用于我的图像

javascript - Bootstrap 3 - 最大化窗口时导航对齐未正确显示