Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a link-style, only for a certain class

Tags:

html

css

I want to change the link-style for some of my links, like this:

a:hover
{
    /* These links will be blue when hovered-over */
    background-color: #3366FF;
}

However, I only want this to take effect in my Navigation Bar, and not for regular links.

I have tried variations on this:

#navbar a:hover
{
    /* These links will be blue when hovered-over */
    background-color: #3366FF;
}

With the intended meaning "this only applies to links with <div id="navbar">"
But it didn't work.

How can I set the style for only certain links, defined by the class or id of their container?

like image 744
abelenky Avatar asked Apr 03 '10 15:04

abelenky


People also ask

How do I change the link color of a specific class in a Div CSS?

You've probably noticed links changing color when you place your cursor on them, a stylish effect and one that's very easy to implement using CSS. To change the color of your link on hover, use the :hover pseudo property on the link's class and give it a different color.

How do you style a specific class?

To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)

How do you make a hyperlink different on each page?

To do this, position your cursor on the page where you would like the link to appear, and then go to Insert > Link. In the window that appears, enter the text you would like to appear as a link, and in the URL Field, enter #targetname, where targetname is the name of your target.


1 Answers

That looks ok to me, Robusto has a valid point with the colour used.

Another method is giving the links a class of their own, eg:

CSS

a.navlink:visited 
a.navlink:hover
{
    background-color: #3366FF; 
}

HTML

<a href="index.html" class="navlink">Home</a>
like image 113
Paul Avatar answered Nov 15 '22 22:11

Paul