html - 在 CSS 中更改图形的大小不会影响其中的图像大小

标签 html css

当我在 CSS 中缩小图形的大小时,其中的图像保持原始大小

HTML:

<!DOCTYPE html>
<html>
    <link href="style.css" rel="stylesheet">

<head>

</head>

<body>
    <div id="wrapper" style="text-align: center">
        <p>        
            Piece of text inside a 500px width div centered on the page
        </p>

        <figure>
            <img src="https://www.newton.ac.uk/files/covers/968361.jpg">
        </figure>
    </div><!--wrapper-->
</body>
</html>

CSS:

#wrapper {
    width: 900px;
    margin: 0 auto;
}

figure {
    float: left;
    display: inline-block;
    width: 12px;
    height: auto;
}

p {
    clear: both;
}

当我修改css中的width属性时,它不会影响网站上显示的图像的大小。

最佳答案

宽度高度分配给您的img。现在,每当您更改 figure heightwidth 时,都会根据它进行更改。

figure > img{
  width:100%;
  min-height:100%;
}

关于html - 在 CSS 中更改图形的大小不会影响其中的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38711342/

相关文章:

html - 如何调整矩形图像以在类似 instagram 的图像网格中显示为正方形而不丢失页面响应能力

javascript - 使 Bootstrap 进度条从 0 到 100% 动画

html - 使用 HTML5 的实时音频流

javascript - 将表格中的元素居中对齐

css - 为什么这个 float 的 parent 在考虑 sibling 之前先计算它的宽度?

html - div 的最小高度 100%

javascript - 淡入不起作用

css - 带有轮廓和伪元素的 Firefox 中的奇怪行为

javascript - 图像在全宽上扩展了链接触发范围

jquery - 背景图像调整大小取决于屏幕