Using an image caption in Markdown Jekyll

后端 未结 10 872
一个人的身影
一个人的身影 2021-01-29 18:11

I am hosting a Jekyll Blog on Github and write my posts with Markdown. When I am adding images, I do it the following way:

![name of the image](http://link.com/ima

相关标签:
10条回答
  • 2021-01-29 18:19

    You can use table for this. It works fine.

    | ![space-1.jpg](http://www.storywarren.com/wp-content/uploads/2016/09/space-1.jpg) | 
    |:--:| 
    | *Space* |
    

    Result:

    0 讨论(0)
  • 2021-01-29 18:20
    <p align="center">
      <img alt="img-name" src="/path/image-name.png" width="300">
      <br>
        <em>caption</em>
    </p>
    

    That is the basic caption use. Not necessary to use an extra plugin.

    0 讨论(0)
  • 2021-01-29 18:26

    I know this is an old question but I thought I'd still share my method of adding image captions. You won't be able to use the caption or figcaption tags, but this would be a simple alternative without using any plugins.

    In your markdown, you can wrap your caption with the emphasis tag and put it directly underneath the image without inserting a new line like so:

    ![](path_to_image)
    *image_caption*
    

    This would generate the following HTML:

    <p>
        <img src="path_to_image" alt>
        <em>image_caption</em>
    </p>
    

    Then in your CSS you can style it using the following selector without interfering with other em tags on the page:

    img + em { }
    

    Note that you must not have a blank line between the image and the caption because that would instead generate:

    <p>
        <img src="path_to_image" alt>
    </p>
    <p>
        <em>image_caption</em>
    </p>
    

    You can also use whatever tag you want other than em. Just make sure there is a tag, otherwise you won't be able to style it.

    0 讨论(0)
  • 2021-01-29 18:26

    A slight riff on the top voted answer that I found to be a little more explicit is to use the jekyll syntax for adding a class to something and then style it that way.

    So in the post you would have:

    ![My image](/images/my-image.png)
    
    {:.image-caption}
    *The caption for my image*
    

    And then in your CSS file you can do something like this:

    .image-caption {
      text-align: center;
      font-size: .8rem;
      color: light-grey;
    

    Comes out looking good!

    0 讨论(0)
提交回复
热议问题