[SOLVED] CSS: How to wrap text around image with caption

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
benali72
Level 4
Level 4
Posts: 278
Joined: Sat Mar 23, 2013 11:49 am

[SOLVED] CSS: How to wrap text around image with caption

Post by benali72 »

Does anyone know how to code CSS to wrap text around an image that has a caption at the bottom of it?

So -- I'm trying to add a caption underneath a figure (using figcaption). Then I want the text to flow around the figure and its caption.

I seem to be able to EITHER have the caption at the bottom of the figure --OR-- have the text flow around the figure... but not both.

Thank you.
Last edited by LockBot on Wed Sep 20, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
axrusar
Level 7
Level 7
Posts: 1512
Joined: Sat Jan 30, 2021 5:30 pm

Re: CSS: How to wrap text around image with caption

Post by axrusar »

Try tweaking this:

Code: Select all

<style>
    figure {
      float: left;
      margin: 0 20px 20px 0;
      text-align: center;
    }

    figcaption {
      font-style: italic;
      text-align: center;
    }

    figure:last-of-type {
      clear: both;
    }
  </style>
Then for the image HTML:

Code: Select all

<figure>
    <img src="example.jpg">
    <figcaption>Example Caption</figcaption>
  </figure>
Linux Mint Una Cinnamon 20.3 Kernel: 5.15.x | Quad Core I7 4.2Ghz | 24GB Ram | 1TB NVMe | Intel Graphics
Image
benali72
Level 4
Level 4
Posts: 278
Joined: Sat Mar 23, 2013 11:49 am

Re: [SOLVED] CSS: How to wrap text around image with caption

Post by benali72 »

Thank you so much !

That worked perfectly.

I was wracking my brain on this one.... it seems there are so many CSS attributes and I just couldn't find the one I needed.

Thank you again!
Locked

Return to “Other topics”