Image caption width to same as image

前端 未结 6 748
生来不讨喜
生来不讨喜 2020-12-25 13:16

How can I make image caption width same as image? Now I have the following code:

\"\" &
6条回答
  •  再見小時候
    2020-12-25 13:58

    The key is to treat the image as having a certain width some length. In the example below I checked and my image was 200px wide. And then treat the caption as an inline-block.

    HTML:

    Image description
    This can be as long as you want.

    CSS:

    .caption {
       display: inline-block;
    }
    

    You can also replace the inline-block with text that is left justified, right, or stretched over the exact image width by replacing above css with one of the following:

    .caption {
       /* text-align: left; */
       /* text-align: right; */
       text-align: justify;
    }
    

提交回复
热议问题