Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:58:19+00:00 2026-05-24T15:58:19+00:00

<style> .btn{ display: inline-block; padding: 15px 10px; background: gray; } .btn:hover{ background:lightgray; color:red; }

  • 0
<style>
      .btn{
           display: inline-block;
           padding: 15px 10px;
           background: gray;
       }
      .btn:hover{
             background:lightgray;
             color:red;
      }
</style>

<div class="btn"> 
   text
</div>

works nicely. However if we have that:

<div class="btn"> 
  <a href="#">text</a>
</div>

it wouldn’t work exactly as the first one. The anchor’s text wouldn’t be affected. Okay what if we add to the CSS:

.btn a:hover{
    background:lightgray;
   color:red;
 }

That will work, but only if you hover exactly on the anchor, but still hover on the div rectangle wouldn’t affect the anchor’s text.

How can I tweak that without any javascript, so both rectangles acted identically?

http://jsfiddle.net/vaNJD/

UPD: adding !important keyword wouldn’t help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:58:20+00:00Added an answer on May 24, 2026 at 3:58 pm

    Because all web browsers set a default color (and text-decoration) for a elements, you need a more specific selector to override the default. Try this instead:

    .btn:hover, .btn:hover a {
        background:lightgray;
        color:red;
    }
    

    If you really want the two boxes to be identical, you would also need to override the un-hovered button as well:

    .btn a {
        color: black;
        text-decoration: none;
    }
    

    It may also be worth pointing out that IE6 only supports the :hover pseudo-class on a elements. You may want to work around this by setting the a to display: block and adding the background color there.

    You can accomplish the same effect by getting rid of the container and applying the .btn class directly to the a element. See the third box in this updated fiddle: http://jsfiddle.net/mlms13/vaNJD/5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this div... <div tabindex=0 class=button-base inline-block button aw-btn button-base-active> <input type=text tabindex=-1
I have the following html and css <div id=header> <div id=headerTopLeft> <div id=areaSelect style=display:
I have style my radio buttons with a background image, basically what i have
  I understand that elements can have multiple classes: .rfrsh-btn { background-image:url(../../upload/rfrsh_nb_grey.png); ... }
I know you can access page resources by using the following code: btn.Style =
I have a div with a CSS style to show it as a button:
(Jeopardy-style question, I wish the answer had been online when I had this issue)
Out style: bool result; if(something.TryParse(val, out result)) { DoSomething(result); } Nullable style: bool? result
My style of coding includes the following idiom: class Derived : public Base {
Which style of Ruby string quoting do you favour? Up until now I've always

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.