Other links

2022-02-06
1 min read

Mermaid

Mermaid: Create diagrams quickly and effortlessly

Images

Centering images in Hugo

...

the solution

in the end, after some energetic googling i did cobble together something that gets the job done with minimal markup and no extraneous tags in the content.

to be able to center images in a Hugo-based blog or float them left/right (read: align left/right with text wrapping around them ), add the following to your CSS (typically under static/css/ on your side, or wherever the theme you’re using keeps its own stylesheets if you’re hacking the theme CSS directly):

img[src$='#center']
{
    display: block;
    margin: 0.7rem auto; /* you can replace the vertical '0.7rem' by
                            whatever floats your boat, but keep the
                            horizontal 'auto' for this to work */
    /* whatever else styles you fancy here */
}

img[src$='#floatleft']
{
    float:left;
    margin: 0.7rem;      /* this margin is totally up to you */
    /* whatever else styles you fancy here */
}

img[src$='#floatright']
{
    float:right;
    margin: 0.7rem;      /* this margin is totally up to you */
    /* whatever else styles you fancy here */
}

then, inside your Markdown content, pull in the images as follows:

![your_img](/img/your_img.png#center)
![your_img](/img/your_img.png#floatleft)
![your_img](/img/your_img.png#floatright)

Responsive Images in Hugo