Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style HTML element based on its title using CSS

Tags:

html

css

Is it possible to apply a style to an HTML element using only its title as a unique identifier? For example:

<div class="my_class">
    <a href="some site" title="MyTitle">My Link</a>
</div>

I would like to write a rule that will apply only to link element within a div of class my_class and the link title MyTitle.

I do not have the ability to change page layout, however, I can use a custom CSS file that is included automatically.

Thank you

like image 270
Misha M Avatar asked Mar 08 '09 02:03

Misha M


People also ask

How do you change the style of the title attribute?

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.

What is the CSS selector for an a tag containing the title attribute?

CSS [attribute~=value] Selector The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.

How do you decorate a title in HTML?

For this content, we'll use the <h1> heading element, the <p> paragraph element, and the <em> emphasis element. Make sure to change the text with your own information. The elements used in this code snippet apply some light styling to our title and subtitle.


1 Answers

It sure is, using what's called attribute selectors; these are part of CSS2. In your particular case, you'd use:

div.my_class a[title="MyTitle"] { color: red; }

You can read more about attribute selectors here: http://www.w3.org/TR/CSS2/selector.html#attribute-selectors

like image 73
John Feminella Avatar answered Sep 17 '22 17:09

John Feminella