【问题标题】:css hover effect happening outside of buttonCSS悬停效果发生在按钮之外
【发布时间】:2016-06-18 10:38:14
【问题描述】:

我当前的代码在链接的顶部和底部生成一个元素(黑条)。底部栏始终存在,顶部栏仅在悬停时出现。

我的代码工作正常,但只要光标与链接一致,就会出现悬停效果(“命中”框似乎是屏幕的 100% 宽度,即使按钮只是文本)

#contact-btn a {
position: relative;
font-family: 'Montserrat', sans-serif;
display: inline-block;
font-size: 3em;
letter-spacing: 1px;
font-weight: 400;
color: #4d4d4d;
}

#contact-btn a:after, #contact-btn a:before   { 
display: block;
position: absolute;
content: '';
margin: 0 auto;
background-color: #4d4d4d;
}

#contact-btn a:after { 
height: 2px; width: 100px;
bottom: -15px; left: 0; right: 0; 
}

#contact-btn a:before { 
height: 2px; width: 0;
top: -15px; left: 0; right: 0; 
}

#contact-btn:hover a:after, #contact-btn:hover a:before { width: 175px; height: 2px; }

html

<div id="contact-btn">
    <a href="mailTo:..."> Click here </a>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    您还没有为contact-btn div 本身设置任何样式。 试试这个

    #contact-btn {
       display: inline-block;
       position: relative; 
    }
    

    【讨论】:

    • 欢迎你,你可以投票给答案:p
    猜你喜欢
    • 2014-07-05
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    相关资源
    最近更新 更多