Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to style a title? (and with CSS or js?) [duplicate]

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:

  • Text formatting / encoding (Which I guess is possible SO does it in questions*).
  • The Tooltip styling, can you make it bigger? other colors? etc.

And the other issue I have is how do you "point" to title?

  • From CSS
  • From Javascript / jQuery

Thanks in advance!


*What I ment by text formatting / encoding:

alt text

like image 385
Trufa Avatar asked Dec 08 '10 00:12

Trufa


People also ask

Can you style title in CSS?

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.

Can you style JavaScript with CSS?

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.

How do you write a title in CSS?

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.


2 Answers

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&#13;&#10;this&#13;&#10;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.

like image 147
Phrogz Avatar answered Sep 20 '22 14:09

Phrogz


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.

like image 37
Shimon Rachlenko Avatar answered Sep 20 '22 14:09

Shimon Rachlenko