Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an abbr tag's title be styled?

Tags:

css

abbr

Take the following code:

<abbr title="World Health Organization">WHO</abbr>

Can we style an abbr tag's title? So that instead of a custom tooltip we can use title?

like image 823
Joemon Avatar asked Nov 05 '09 18:11

Joemon


People also ask

How we can style any abbreviation element that have a title attribute?

The <abbr> tag defines an abbreviation or an acronym, like "HTML", "CSS", "Mr.", "Dr.", "ASAP", "ATM". Tip: Use the global title attribute to show the description for the abbreviation/acronym when you mouse over the element.

Is abbr a block element?

HTML abbr element can reside within inline as well as block level elements.

How do you remove the underline from an abbr tag?

By default, the <abbr> tag adds an underline to the text. This can be removed using the CSS property text-decoration . An <abbr> element without underline.

Which of the following is used to reference data that can act as an abbreviation?

ENTITY Declaration. Entities reference data that act as an abbreviation or can be found at an external location.


1 Answers

I was looking for something similar and came up with the following alternative (tested on Firefox, Safari and Chrome on Mac, works with IE 7-10 when I clicked it), based on this link:

HTML:

<abbr title="My Custom Abbreviation" name="">Abbreviation</abbr>

jQuery:

$('[title]').each( function() {
    var mytitle = $(this);
    mytitle.data('title',mytitle.attr('title')); // get title attribute value
mytitle.attr('name', mytitle.attr('title')); // add title attribute value to NAME attribute
    mytitle.removeAttr('title'); // remove the title attribute, removing browser tooltip
});

CSS:

abbr {
    position: relative;
}
abbr:hover::after {
    position: absolute;
    bottom: 100%;
    left: 100%;
    display: block;
    padding: 1em;
    background: yellow;
    content: attr(name);
}
like image 104
davewoodhall Avatar answered Oct 02 '22 18:10

davewoodhall