简体   繁体   English

将标题垂直居中对齐

[英]Align Caption Left of Vertically Centered Image

In the following example, is there an easy way to align the caption with the left edge of the centered image? 在下面的示例中,是否有一种简单的方法将标题与居中图像的左边缘对齐?

Currently the display looks like this: 当前显示如下:

      ____________________
     |                    |
     |                    |
     |                    |
     |                    |
     |____________________|
 This is my caption

I'd like it to look like this 我希望它看起来像这样

  ____________________
 |                    |
 |                    |
 |                    |
 |                    |
 |____________________|
 This is my caption

 .container{ width: 100%; height:200px; } img{ width: 400px; height:50px } .figure{ text-align: center; } .caption{ text-align: left; } 
 <div class="container"> <figure class="figure"> <img src=""/> <figcaption class="caption"> This is my caption. </figcaption> </figure> 

You could do it like this. 您可以这样做。

 .container{ width: 100%; height:200px; } #imgWrap { display: inline-block; } img{ width: 400px; height:50px } .figure{ text-align: center; } .caption{ text-align: left; } 
 <div class="container"> <figure class="figure"> <div id='imgWrap'> <img src=""/> <figcaption class="caption"> This is my caption. </figcaption> </div> </figure> </div> 

The text-align property aligns the "figure" to the center as it is specified as 'center'. text-align属性将“数字”与中心对齐,因为它被指定为“中心”。

So change it to 'left' or don't specify it at all. 因此,将其更改为“左”或根本不指定它。

 .container{ width: 100%; height:200px; } img{ width: 400px; height:50px } .figure{ } .caption{ } 
 <div class="container"> <figure class="figure"> <img src=""/> <figcaption class="caption"> This is my caption. </figcaption> </figure> 

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

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