Reputation: 623
I made a css button, but I can't figure out how to change the text color to white when I hover over the button.
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
When I add color to
a.button1o:hover
it doesn't work.
I also tried:
Upvotes: 0
Views: 658
Reputation: 201
You put on hover wrongly. You are putting hover on .button1o class but .button1o-text this class is overriding .button1o this color
Please put your code this way
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
a.button1o:hover {
background-color: #f44336;
}
span.button1o-text:hover {
transition: all 0.9s ease 0.1s;
color:#fff;
}
Upvotes: 1
Reputation: 111
You do not need the span class="button1o-text... Simply integrate settings into the button1o class and add color:white to the a.button1o:hover class.
<a class="button1o" href="" target="_blank">Flat button</a>
You might need adding the text-decoration:none attribute into the button1o defintions too.
Upvotes: 0
Reputation: 2534
You can use the :hover
selector on the parent element:
a.button1o:hover .button1o-text {
color: white;
}
Also you should put the transition
property inside your first declaration, otherwise you will lose the transition when the user stops hovering over the button.
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
transition: all 0.9s ease 0.1s;
}
a.button1o:hover {
background-color: #f44336;
}
a.button1o:hover .button1o-text {
color: white;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
Upvotes: -1
Reputation: 522
Check this fiddle.
CODE
This should work as you wanted, tell me if it does, thank you.
a.button1o:hover{
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
a.button1o:hover .button1o-text{
color: #fff;
transition: all 0.9s ease 0.1s;
}
Upvotes: 0
Reputation: 7766
you need to add the hover property to span element. that is :
a.button1o>span:hover {
color:white;
}
Here is a your working code from the question
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
color:white;
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
a.button1o>span:hover {
color:white;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
Upvotes: 0
Reputation: 18649
You have two options. The cleaner option is to move the color: #f44336
rule out of .button1o-text
and onto .button1o
, which will allow the current hover rule to override the color. (Is there a reason you have a span with separate CSS rules at all?)
The other option is to add this hover rule to color the text:
.button1o:hover .button1o-text {
color: [hover color];
}
Upvotes: 0
Reputation: 14368
That is because you are applying the color on the a
not the span
try this
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
color: #f44336;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
color: #fff;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
}
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
In the above snippet i added color:#fff
to a.button1o:hover
and also i added #f44336
to .button1o
Another method is like this
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
color: #fff;
}
a.button1o:hover span {
transition: all 0.9s ease 0.1s;
color: #fff;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
Upvotes: 1