tags:

views:

113

answers:

8

Hi

i have a a:hover for all my links on my page:

a:hover {
  background-color: blue;
  text-decoration: underline;
  color: black;
}

but but there are specific ones in a div that i don't want anything to happen when you hover over them, so can i do something like this?

#what_we_offer a:hover {
  background-color: none:
  text-decoration: none;
  color: none;
}

basically i don't want it to do any of the above when it hovers over them specific links.

thanks

+6  A: 

Yes that should work fine, although you likely don't want to set none unless you really don't want any style... setting your base colors etc. should work fine.

#what_we_offer a:hover {
  background-color:#fff;/*presuming was originally white*/
  text-decoration:none;
  color:#000;/*presuming was originally black*/
}

PS I'm not sure if it was just a typo, but your original background-color:none: line was terminated with a colon vs. a semi-colon thus it would have caused issues.

scunliffe
that didn't work for me, the 'none' attributed dose not work.
Mo
First is your "override" for the "#what_we_offer" after the default :hover or before it? Second, if you use my code above, what do you get?
scunliffe
+2  A: 

Rather than using id with css use Class

/* for link where you want to change color on hover */
    .Link a:hover { 
      background-color: none: 
      text-decoration: none; 
      color: red; 
    } 

/* for link where you dont want to change color on hover */
    a:hover { 
      background-color: none: 
      text-decoration: none; 
      color: none; 
    } 
Pranay Rana
as for `id` vs. `class` - it all depends if @Mo has 1 special div or a collection of special divs.
scunliffe
the 'none' attributed for background-color dose not work
Mo
yes its a special div and that's why i used ID.
Mo
A: 

Yes but beware that a:hover{} should come before #what_we_offer a:hover {}.

ttchong
Since they have different specificities, the order really doesn't matter.
David Dorward
@David Dorward: thanks for noted about this.
ttchong
A: 

Hi ..

a:hover { background-color: none: text-decoration: none; color: none; }

this is currect............

you want only particular page so please add

body-id a:hover { background-color: none: text-decoration: none; color: none;

} 

Thanks ptiwari

Prashant
It isn't correct (none is not a color), you want to use a id selector, not a type selector, the question says *div* not *page* and you haven't formatted your code.
David Dorward
Your answer is not correct. If he has a default background color, text decoration etc. for that div then it will fade way when the mouse is moved over that div. All these properties should be set to the default properties for that div in the "a:hover" block.
Night Shade
A: 

I think if you do the reverse of what Pranav said, you can have less modifications i,e



/* for link where you ***DO*** NOT want to change color on hover */
    .Link a:hover { 
      background-color: none: 
      text-decoration: none; 
      color: red; 
    } 

/* for link where you want to change color on hover */
    a:hover { 
      background-color: none: 
      text-decoration: none; 
      color: none; 
    }

so you need to add class for a href s in some particular DIVs

kantu
A: 

You can make use of CSS selectors. The best thing I think you can do is to use the selector not. Let me show you an example:

<html>
        <head>
                <style type="text/css">
                        a:not([not_custom]){
                                background: #00FF00;
                                color: #FF0000;
                        }                    
                </style>
        </head>
        <body>
                <div>
                        <a href="">Test 1</a>
                        <a href="" not_custom="">Test 2</a>
                        <a href="">Test 3</a>
                        <a href="" not_custom="">Test 4</a>
                        <a href="">Test 5</a>
                        <a href="" not_custom="">Test 6</a>
                </div>
        </body>
</html>

As you can see, I'm defining the a style using the not selector. So, I'm saying that I want to put a green background and a red color to all the a that doesn't have the attribute not_custom. As a result of this, you can see that Test 1, Test 3 and Test 5 will have the style defined and Test 2, Test 4 and Test 6 will be normal, without the style.

NOTE: you can define the attribute you want. You don't have to named not_custom. It can be called whatever if you want.

Harph
Don't make up attributes when you are writing HTML (unless you are writing HTML5 (even though it is still a draft) and you conform to its limitations on what custom attributes may be named (which you don't). `:not` isn't really widely supported enough to serious use yet (especially if you end up with unreadable text if it fails, which might be the case in this situation)
David Dorward
A: 
#what_we_offer a:hover {
  background-color: transparent;
  text-decoration: none;
  color: none;
}

use transparent instead of none, that works.

thanks for all the answers.

Mo
A: 

When you want to override CSS values you can do two things: adding new CSS declarations after the one you want to override or using "!important".. So for your problem you can try:

a.reset:hover {
 background-color: #FFFFFF;
 text-decoration: none;
 color: #000000;
}

.. and then add the links you want to override this new class:

<a href="#" class="reset">Link with reset</a>

But this CSS class must be declared after you normal "a" tag declarations or this won't work.

Another way is to use !important but I recommend not to abuse this one. But for overriding it's the fastest and safest way to be sure it will work:

a.reset:hover {
 background-color: #FFFFFF !important;
 text-decoration: none !important;
 color: #000000 !important;
}

.. and this one you can add anywhere in your CSS file and any link with the "reset" class will get those styles: white background, no text decoration and black text.

Oh and for the background you cand try: background: none; and will clear all background styles.. background-color, background-image, etc

As a side note.. id's are used to reference a single element and it must be unique.. and classes are used to reference multiple elements. Multiple uses of the same id as you would use a css class.. you can brake javascript and it won't validate your HTML.

forapathy