Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of element when hovering over another element?

Tags:

html

css

I am trying to make a button that has a white background and an orange icon when not being hovered and has an orange background and a white icon when hovered over. The behavior is very similar to the behavior seen when scrolling over one of the glyphicons found here. http://getbootstrap.com/components/

The two problems I am encountering is that the text is highlighted blue when scrolled over and that I can only change the background to orange and not the icon color at the same time. The icon is a glyphicon. Does anyone know how to accomplish what I am trying to do?

This is the block of html I am working with.

  <div class="col-xs-4">
        <a href="/pace">
            <div class="calc-btn">
                <span class="glyphicon glyphicon-time" style="font-size:100px;"></span>
                <span class="text-under-gylphicon">Pace</span>
            </div>
        </a>
    </div>

and the corresponding css

.text-under-gylphicon{
    display: block;
}

.calc-btn, .calc-btn a{
    margin: 10px 0;
    padding: 10px;
    font-size: 33px;
    line-height: 1.4;
    text-align: center;
    background-color: #f9f9f9;
    list-style-type: none;
    list-style-position: outside;
    border: 1px solid #fff;
    text-decoration: none;
}

.calc-btn:hover {
    background-color: #EF5E2F;
    text-decoration: none;
}   

.calc-btn:hover::after {
    color: #FFFFFF;
}
like image 515
Xerunix Avatar asked Mar 15 '23 10:03

Xerunix


2 Answers

Here, you just need a hover and to set the color in the CSS.

fiddle: https://jsfiddle.net/heh66yc8/

HTML:

<div class="col-xs-4">
        <a href="/pace">
            <div class="calc-btn">
                <span class="glyphicon glyphicon-time glyph"></span>
                <span class="text-under-gylphicon">Pace</span>
            </div>
        </a>
    </div>

CSS

.text-under-gylphicon{
    display: block;
}

.calc-btn, .calc-btn a{
    margin: 10px 0;
    padding: 10px;
    font-size: 33px;
    line-height: 1.4;
    text-align: center;
    background-color: #f9f9f9;
    list-style-type: none;
    list-style-position: outside;
    border: 1px solid #fff;
    text-decoration: none;
}

.glyph
{
    color:#EF5E2F;
    font-size:100px;
}

.calc-btn:hover {
    background-color: #EF5E2F;
    text-decoration: none;
}

.calc-btn:hover .glyph {
    color: #fff;
}  
like image 113
Jesse Avatar answered May 04 '23 12:05

Jesse


Try this

.calc-btn a{
text-decoration:none;
color:inherit;
}
.calc-btn{
color:orange;
background-color:#fff;
}

.calc-btn:hover{
color:#fff;
background-color:orange;
}
like image 39
Alexis Avatar answered May 04 '23 10:05

Alexis