简体   繁体   English

如何将带有标题的图形居中?

[英]How can I center a figure with caption?

I have this HTML and CSS: 我有这个HTML和CSS:

 figure { display:inline-block; margin: 0 auto; } figure img { display:block; margin:0 auto; border-radius: 100%; } figcaption { display:block; padding:8px; } 
 <figure> <img src="me.jpg" alt="Author Of The Blog" height="200" width="200"> <caption>Me and the co-author of this blog, Pepe</caption> </figure> 

My problem is that the figure is not centered, how can I do that? 我的问题是这个数字没有居中,我该怎么做? I also need to center the caption along with the photo. 我还需要将标题与照片对齐。 Thx a lot. 多谢。

I believe you set figure display property to inline-block for reason. 我相信您将figure显示属性设置为inline-block是有原因的。 If so all you need to do is to set parent container text-align property to center : 如果是这样,您只需将父容器text-align属性设置为center

 .container { text-align: center; } figure { display:inline-block; margin: 0 auto; } figure img { display:block; margin:0 auto; border-radius: 100%; } figcaption { display:block; padding:8px; } 
 <div class="container"> <figure> <img src="http://lorempixel.com/200/200" alt="Author Of The Blog" height="200" width="200"> <caption>Me and the co-author of this blog, Pepe</caption> </figure> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM