0

I'd like to use the title attribute content of an img tag to write a legend under the image:

<img title="This is my cat's legend" src="pet-cat-eye.jpg"/>

must be displayed as bellow :

  +--------------+
  |              |
  |     _ _/|    |
  |    \'o.0'    |
  |    =(___)=   |
  |      U U     |
  +--------------+
This is my cat's legend

And i'd like to use CSS only. Is it possible to achieve ?

I've tried some experiment around the img[title*=legend] but did not get to be displayed as I would like to...

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
McGivrer
  • 13
  • 4

1 Answers1

-1

Hi and welcome to StackOverFlow !

The image attributes aren't mean to be displayed under the picture.
Instead you could use something like a <figcaption> under the image declaration to put it under your picture.

With this in mind, you code your code will kind of look like this :

<figure>
  <img alt="cat picture" src="pet-cat-eye.jpg"/>
  <figcaption>This is my cat's legend</figcaption>
</figure>

Let me know if that work !

For further note : The title attribute is used when you mouse hover a picture as a tooltip.

Djamel
  • 798
  • 8
  • 21
  • `` shouldn't be used for this, we have [`
    ` and `
    `](https://www.w3.org/TR/html5/grouping-content.html#the-figure-element) which are designed for this.
    – Quentin Jan 08 '19 at 15:40
  • "title isn't really often used on an image" — It is used quite a lot. – Quentin Jan 08 '19 at 15:41
  • 1
    "The alt attribute stand for the case were it's not possible to load the picture" — … so its wildly inapropriate for the purpose the OP intends. `title` is a better fit. – Quentin Jan 08 '19 at 15:41
  • 1
    I think Crawlers don't mind if the caption is in a `` tag, as long as it is after the `` tag and they are both in a container, like a `
    `
    – xaddict Jan 08 '19 at 15:45
  • 1
    @xaddict — It's possible to write an HTML document with nothing by `` and CSS. Crawlers won't mind about that either. That doesn't make it a good idea. – Quentin Jan 08 '19 at 15:47
  • @quentin Have edited has suggested – Djamel Jan 08 '19 at 15:48
  • 1
    Thanks all for your answers, I'll go and choose the latest
    / solution.
    – McGivrer Jan 14 '19 at 12:54