How to place an item in a breadcrumb menu with a different color without the Hover

Asked

Viewed 311 times

1

I have a menu of this kind, but I don’t want to use the state of hover. It will serve only for page information, no need to click.

However, I’m not getting a different color on one of the menus without using a hover. I’ve tried using a different class with a different color, and I’m not getting it.

Below my code:

<html><head><meta http-equiv="Content-Type" content="text/html;">
        <meta charset="utf-8">

<title>breadcrumbs</title>
    <style type="text/css">

    body{
        font-family:Arial, Helvetica, sans-serif;

        }
    #crumbs ul li a {
    display: block;
    float: left;
    height: 15px;
    background: #999;
    text-align: center;
    padding: 20px 30px 0 20px;
    position: relative;
    margin: 0 10px 0 0; 
    font-size: 18px;
    text-decoration: none;
    color: #fff;
    line-height: 1px;
    cursor:default;
}

    #crumbs ul li a:after {
    content: "";  
    position: absolute; right: -17px; top: 0;
    border-top: 17px solid transparent;
    border-bottom: 17px solid transparent;
    border-left: 17px solid #999; 
    z-index: 1;
}
    #crumbs ul li a:before {
    content: "";  
    border-top: 17px solid transparent;
    border-bottom: 17px solid transparent;
    border-left: 17px solid #fff;
    position: absolute; left: 0; top: 0;
}

    #crumbs ul li {
    display:inline;
}

    #crumbs ul li a:hover {
    background: #779519;
}
    #crumbs ul li a:hover:after {
        border-left-color: #779519;
    }    


    #crumbs ul li:first-child a {
    border-top-left: 10px; border-bottom-left: 10px;
}
#crumbs ul li:first-child a:before {
    display: none; 
}

#crumbs ul li:last-child a {
    padding-right: 80px;
    border-top-right: 10px; border-bottom-right: 10px;
}
#crumbs ul li:last-child a:after {
    display: none; 
}

    </style></head>

<body>
    <div id="crumbs">
    <ul>
        <li><a href="#">Tipo de Bilhete / Zona</a></li>
        <li><a href="#">Sector</a></li>
        <li><a href="#">Lugar</a></li>
        <li><a href="#">Dados de Reserva</a></li>
        <li><a href="#">Confirmação</a></li>
        <li><a href="#">Pagamento</a></li>

    </ul>
</div>
</body></html>
  • Although I can’t figure out why you want the Hover if you’re not going to use that state. It doesn’t make much sense. Anyway you can use javascript and add a class by JS. Anyway, the Hover event will be triggered.

  • I got it, thanks.

  • 3

    Share the answer!

2 answers

2


Just insert a class="active" in the read you want to highlight. In the CSS

#crumbs ul li.active a {...}

Your code with the change:

<html><head><meta http-equiv="Content-Type" content="text/html;">
        <meta charset="utf-8">

<title>breadcrumbs</title>
    <style type="text/css">

    body{
        font-family:Arial, Helvetica, sans-serif;

        }
    #crumbs ul li a {
    display: block;
    float: left;
    height: 15px;
    background: #999;
    text-align: center;
    padding: 20px 30px 0 20px;
    position: relative;
    margin: 0 10px 0 0; 
    font-size: 18px;
    text-decoration: none;
    color: #fff;
    line-height: 1px;
    cursor:default;
}

    #crumbs ul li a:after {
    content: "";  
    position: absolute; right: -17px; top: 0;
    border-top: 17px solid transparent;
    border-bottom: 17px solid transparent;
    border-left: 17px solid #999; 
    z-index: 1;
}
    #crumbs ul li a:before {
    content: "";  
    border-top: 17px solid transparent;
    border-bottom: 17px solid transparent;
    border-left: 17px solid #fff;
    position: absolute; left: 0; top: 0;
}

    #crumbs ul li {
    display:inline;
}

    #crumbs ul li a:hover {
    background: #779519;
}
    #crumbs ul li a:hover:after {
        border-left-color: #779519;
    }    


    #crumbs ul li:first-child a {
    border-top-left: 10px; border-bottom-left: 10px;
}
#crumbs ul li:first-child a:before {
    display: none; 
}

#crumbs ul li:last-child a {
    padding-right: 80px;
    border-top-right: 10px; border-bottom-right: 10px;
}
#crumbs ul li:last-child a:after {
    display: none; 
}


#crumbs ul li.active a{
    color: #ffcc00;
    background: #000;
}

    </style></head>

<body>
    <div id="crumbs">
    <ul>
        <li><a href="#">Tipo de Bilhete / Zona</a></li>
        <li><a href="#">Sector</a></li>
        <li><a href="#">Lugar</a></li>
        <li><a href="#">Dados de Reserva</a></li>
        <li><a href="#">Confirmação</a></li>
        <li class="active"><a href="#">Pagamento</a></li>

    </ul>
</div>
</body></html>

0

Hello,

From what I understand you want the user to know his location without the Hover. I believe that you have already found the solution, but have not applied.

If you are using a manager for example, the body tag always has a class with page id information for example:

<body class="page-contato"></body>

From there you can have control of the CSS used on the page individually too.

If you are not using any CMS, just use this same logic.

Follow the example: http://jsfiddle.net/AquilesOliveira/pc7vgcxz/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.