html - 悬停效果但禁用文本效果

标签 html css

我希望能够定位我的按钮(id=#btn1#btn2 ..等)和 当我这样做时,它们的不透明度会更改为 .60。我现在的问题是 <span>悬停每个按钮时显示的文本也会发生变化 它的不透明度。你能帮我解决这个问题,这样当我悬停时 在每个按钮上显示的文本不会改变它的不透明度。

如果你能给我指出一种合并所有这些的方法,那就太好了 按钮,这样我就不必在底部附近重复我的代码。

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;
    }

最佳答案

您应该定位背景色。

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

但由于您使用的是图像,因此您可以欺骗系统。

1) 技巧 1 -:使用两张图片,一张透明,一张不透明。悬停透明的。

2) 技巧 2 -: 你可以添加 span 标签并在其上显示不透明度。

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

您将此规则应用于它

.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;
}

关于html - 悬停效果但禁用文本效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30965077/

相关文章:

javascript - jQuery mouseenter 只是闪烁 img

html - Joomla 网站上的响应式菜单

javascript - 中心部门

html - 如何根据 child 的类(class)更改 parent 的 css 属性?

javascript - 在多个页面的js变量html中存储链接名称

html - div 定位不正确

html - 如何更改 RWD 的 Grocery Grocery 模板?

html - 无法摆脱菜单中的列表项高度

asp.net - 如何在 mvc 4 中使用多重选择?

python | Selenium 无法检测到按钮