您的代码确实使图像居中(水平)。但无论如何,我会建议一些改进。
figure
元素中.pic {
display: flex;
justify-content: center;
background-color: #d8bfd8;
}
figure {
margin: 0;
}
<div class="pic">
<figure>
<img src="https://i.guim.co.uk/img/static/sys-images/Books/Pix/pictures/2009/1/19/1232367130592/Portrait-of-Edgar-Allan-P-001.jpg?width=465&dpr=1&s=none" alt="black and white portrait of Edgar Allan Poe">
<figcaption>Picture provided from The Guardian Website</figcaption>
</figure>
</div>
如果您想让标题居中,请尝试以下操作:
figcaption {text-align: center;}