styling an image title attribute using css?

前端 未结 7 1350
猫巷女王i
猫巷女王i 2020-12-14 13:07

I want to style the text we see when we hover over the image. I tried the following but it won’t work:


         


        
7条回答
  •  北海茫月
    2020-12-14 13:23

    From the HTML spec (emphasis mine):

    The title attribute represents advisory information for the element, such as would be appropriate for a tooltip. On a link, this could be the title or a description of the target resource; on an image, it could be the image credit or a description of the image; on a paragraph, it could be a footnote or commentary on the text; on a citation, it could be further information about the source; on interactive content, it could be a label for, or instructions for, use of the element; and so forth. The value is text.

    Ergo, only text is allowed in the title attribute. For a custom HTML tooltip, you must use a custom solution, such as hiding the content by default and showing it on :hover with CSS, or using JavaScript to pull from a data-... attribute.

提交回复
热议问题