0

i am trying to do a hover effect with css something super simply, but i'm over looking something, im trying to have the user to be able to hover over a button and have a light shade of white with an opacity applied. But whenever i am doing so my border of the button disappears, I know this because I am targeting the button element. So how does this work without targeting the button element and still keeping the border from not going away. My jsfiddle link is below.

https://jsfiddle.net/bvcxtds/6Lr501g1/

and here is my markup

<button><a>SIGN UP</a></button>

and my css

button {
    border: 1px solid white;
    background: none;
    border-radius: 25px;
    width: 150px;
}
button > a {
    color: white;
}

button:hover {
    opacity: 0.2;
    background: white;
}
body {
    background: black;
}
1
  • And shouldn't it be ".button", with a period before? Commented Oct 14, 2015 at 20:34

3 Answers 3

3

The opacity applies to the entire element, not only the background. The border doesn't actually disappear, it becomes the same color as the background.

Use a background color with an alpha value instead:

button:hover {
  background: rgba(255,255,255,0.2);
}

Demo: https://jsfiddle.net/6Lr501g1/1/

Sign up to request clarification or add additional context in comments.

Comments

0

Replace 'background' for 'color':

button:hover {
  opacity: 0.2;
  color: white;
} 

3 Comments

The text is already white, and that doesn't keep the opacity from affecting the border.
@Guffa is correct, but thanks for helping me out tho! appreciate it.
True, I dont understand the question.:P
0

small changes a and button

button {
    border: 1px solid white;
    background: none;
    border-radius: 25px;
    width: 150px;
}
button a{
    color:#FFF
}



button:hover {
    opacity: .5;
    background: white;
}
button:hover a{
    color: #060606;
  opacity: 1;
}
body {
    background: black;
}

JSFiddel

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.