I was wondering if it was possible to style a title
:
<a href="#" title="This is a title">Hello</a>
The styling question has two aspects:
And the other issue I have is how do you "point" to title?
Thanks in advance!
*What I ment by text formatting / encoding:
You can't style an actual title attribute How the text in the title attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title attribute.
Ignoring inline styles, the other approach that we can use to introduce elements to the goodness that is CSS styling involves JavaScript. We can use JavaScript to directly set a style on an element, and we can also use JavaScript to add or remove class values on elements which will alter which style rules get applied.
Using Title CSS, you'd do the following: For any global CSS class, use a capitalized name (title case). For any modifier or descendant class, use a lowercase letter for the beginning of th name. This means with Title CSS you capitalize any class name that will get referenced in the stylesheet without a parent class.
You can put newlines in your title attribute via HTML entities to force a line break in the text. Most browsers these days support this. This is the only change you can make to the native tooltip display of the browser.
<a href="real_link" title="check this out">foo bar</a>
See the above example on a web page.
As others have pointed out, there exist a large number of plugins for various JS libraries for making custom HTML tooltips which are styleable. Here is the top hit for the Google search "jquery tooltip plugin", reviewing 10 such plugins.
You can create a CSS-only tooltips using the :after
and :hover
pseudo-class:
<a href="#" class="class-with-tooltip">Link</a>
.class-with-tooltip:hover:after{
content: 'Tooltip';
position: absolute;
padding: 5px;
border: 1px solid gray;
background: whitesmoke;
font-size: 14px;
}
I'm not sure how this going to work in old browsers, but it works in all major browsers.
The position: absolute;
is needed to prevent generated content from pushing the markup after the element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With