skaftisveins
skaftisveins

Reputation: 11

hover effect but disable text effect

I would like to be able to target my buttons (id=#btn1, #btn2..etc) and when I do their opacity changes to .60. My problem now is that the <span> text that displays when each button is hovered, also changes its opacity. Can you help me sort this out so that when I hover over each button the displayed text will not change it's opacity.

Also it would be great if you could point me a way to merge all those buttons so I don't have to keep repeating my code near the bottom.

body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, textarea, blockquote {
    margin: 0; padding: 0; border: 0;
}

body {
    background: url(../img/filter.jpg);
}

.nav {
    width: 1000px; margin: 250px auto;
}

.nav ul {
    list-style: none; overflow: hidden; position: relative;
}
    .nav ul li {
        float: left; margin: 0 20px 0 0;
    }
        .nav ul li a {
            display: block; width: 120px; height: 120px;
        }
            .nav #btn1 {
                background-image: url(../img/icons/home80.png);
                background-position: 28px 28px;
                background-repeat: no-repeat;
            }
            .nav #btn2 {
                background-image: url(../img/icons/truck90.png);
                background-position: 28px 28px;
                background-repeat: no-repeat;
            }
            .nav #btn3 {
                background-image: url(../img/icons/note80.png);
                background-position: 28px 28px;
                background-repeat: no-repeat;
            }
            .nav #btn4 {
                background-image: url(../img/icons/vallet80.png);
                background-position: 28px 28px;
                background-repeat: no-repeat;
            }
                .nav ul li a span {
                    font: 50px "Dosis", sans-serif; text-transform: uppercase; 
                    position: absolute; left: 580px; top: 29px;
                    display: none;
                }
                    .nav ul li a:hover span {
                        display: block;
                        color: #fff;
                        opacity: 1;
                    }
                /*
                .nav nav ul li:nth-child(1) a span {

                }
                .nav nav ul li:nth-child(2) a span {

                }
                .nav nav ul li:nth-child(3) a span {

                }
                .nav nav ul li:nth-child(4) a span {

                }*/
.nav #btn1:hover,
.nav #btn1:focus { opacity: .60; }
.nav #btn2:hover,
.nav #btn2:focus { opacity: .60; }
.nav #btn3:hover,
.nav #btn3:focus { opacity: .60; }
.nav #btn4:hover,
.nav #btn4:focus { opacity: .60; }
.nav ul li a span:hover,
.nav ul li a span:focus { opacity: 1; }

.jumbotron h1 {
    width: 1000px; margin: -580px auto;
    font: 70px "Dosis", sans-serif;
    }
.jumbotron .container h2 {
    width: 1000px; margin: 800px auto;
    font: 32px "Dosis", sans-serif;
    text-shadow: black 0.1em 0.1em 0.2em;
    color: #fff;
    }

Upvotes: 0

Views: 59

Answers (2)

David Addoteye
David Addoteye

Reputation: 1641

You should target the background color.

.nav #btn3 {
    background-color: rgba(0,0,0,0.6);// transparent black.
  }

But since you are using image you can trick the system.

1) Trick 1 -: use two images, one transparent and one opaque. the transparent one for hover.

2) Trick 2 -:you can add span tag and display the opacity on it.

<ul>
  <li id="btn3">
   <a href="">
     <span>Your Link text here</span>
   </a>
  </li>
 </ul>

The you apply this rule to it

.nav li#btn3 span {
  opacity: 0;
  height: 100%;
  width: 100%;
  background-color: #000; /*My is black, you can use any color. black & white are best*/
}

.nav li#btn3:hover span {
  opacity: 0.6;
}

Upvotes: 2

K K
K K

Reputation: 18109

That's not possible. Opacity will affect the text too. Instead of opacity, try changing background-color in rgba format if you want the same effect.

Upvotes: 1

Related Questions