Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Markdown, how do I center an image and its caption?

I want to end up with:

Hello there!        <image>       This is an image  Hi! 

Where the image and the text This is an image are centered on the page. How do I accomplish this with Markdown?

Edit: Note that I'm looking to horizontally center the image and text on the page.

like image 991
Chetan Avatar asked Oct 12 '10 08:10

Chetan


People also ask

Can you center an image in markdown?

Markdown files are rendered by github.com website through the use of the Ruby Redcarpet library. Redcarpet exposes some extensions (such as strikethrough, for instance) which are not part of standard Markdown syntax and provide additional "features". However, no supported extension allow you to center an image.

How do you center something in markdown?

To center images, text, and anything else in Github markdown and READMEs simply wrap the element in an HTML tag with the align attribute set to "center" .

How do you center an image in content?

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.


2 Answers

I figured that I'd just have to use HTML where I want to horizontally align anything.

So my code would look like this:

Hello there!        <center><img src="" ...></center>       <center>This is an image</center>  Hi! 
like image 187
Chetan Avatar answered Sep 18 '22 18:09

Chetan


I think I have a simple solution that will work given that you can define CSS. It also does not require any extensions or HTML! First your markdown image code:

![my image](/img/myImage.jpg#center)   

Note the added url hash #center.

Now add this rule in CSS:

img[src*='#center'] {      display: block;     margin: auto; } 

You should be able to use a url hash like this, almost like defining a class name.

To see this in action, check out my JSFiddle using SnarkDown to parse MarkDown in a textarea - https://jsfiddle.net/tremor/6s30e8vr/

like image 40
tremor Avatar answered Sep 17 '22 18:09

tremor