Jibon
Jibon

Reputation: 342

How to change CSS style without id or class

I want to change background of this 2 link <a href="http://www.domain.com/index.html"> <a href="http://www.domain.com/index.php"> But condition is I can't add any class or Div id here. I can't touch this this html code also. Just I need to add some css from external. I mean in main style.css sheet. Is is possible ? I have tried with this code a { background:url(../images/image.png);} but problem is it's change the whole link's background of the page. But I want 2 different background of the 2 link. Is is really possible. Anyone can help me please :)

Upvotes: 1

Views: 2870

Answers (2)

You need to find a way to differentiate the two links, from the code you posted, they only differ in the url they point to, so you could use this:

/* anchors with href attribute ending in index.html */
a[href$='index.html'] { background:url(../images/image.png);}

/* anchors with href attribute ending in index.php */
a[href$='index.php'] { background:url(../images/image2.png);}

Upvotes: 2

tombeynon
tombeynon

Reputation: 2346

You can use CSS attribute selectors to only style links with an href that matches the links you supplied. Example:

a[href="http://www.domain.com/index.html"],
a[href="http://www.domain.com/index.php"]{
    background:url(../images/image.png);
}

You could also match all links with an href starting with http://www.domain.com using the following rule

a[href^="http://www.domain.com"]{
    background:url(../images/image.png);
}

Please check the support as older browser might ignore attribute selectors.

http://css-tricks.com/attribute-selectors/

Upvotes: 1

Related Questions