简体   繁体   English

CSS / HTML:内部具有跨度,跨度边距的标记,在悬停划线下创建空白

[英]CSS/HTML: a tag with a span inside, span margin creating white space on hover underline

I have a link with a span inside, I want to place a margin on the span so it is distanced from the link title, however, when I use the :hover for underline, a white space is created where there is no underline. 我的链接内部有一个跨距,我想在跨距上放置一个边距,使其与链接标题保持一定距离,但是,当我使用:hover进行下划线时,会在没有下划线的地方创建空白。 I want the underline to be the full width of the link element. 我希望下划线是链接元素的完整宽度。 How do I do this? 我该怎么做呢? Thank you. 谢谢。

http://jsfiddle.net/EY387/ http://jsfiddle.net/EY387/

HTML 的HTML

<div>
    <a href="#" class="link-1">
        <span class="span-1">1</span>
        Hello
    </a>    
</div

CSS 的CSS

.link-1 {
    font-size: 16px;
    text-decoration: none;
}
.link-1:hover {
    text-decoration: underline;
}
.span-1 {
    font-size: 12px;
    margin-right: 5px;
}

Though it may not be exactly what you're looking for, why not try a border? 尽管它可能并非您要找的东西,但为什么不尝试使用边框呢?

HTML 的HTML

<div>
    <a href="#" class="link-1">
        <span class="span-1">1</span>
        Hello
    </a>    
</div>

CSS 的CSS

.link-1 {
    font-size: 16px;
    text-decoration: none;
}
.link-1:hover {
    border-bottom:1px solid #000;
}
 .span-1 {
    font-size: 12px;
    margin-right: 5px;
}

Demo As @DavidThomas explained, if having a border move elements underneath is a problem, the use of a box-shadow could be easily swapped for the border-bottom. 演示正如@DavidThomas解释的那样,如果在下面使用边框移动元素是一个问题,则可以轻松地将盒子阴影的使用替换为边框底部。 Illustrated here 图示在这里

Remove margin to span. 删除跨度的边距。 margin space not taking underline on hover. 边距空间不会在悬停时加下划线。

For space use &nbsp; 为了空间使用&nbsp; . As in this following markup: 如以下标记所示:

<div>
    <a href="#" class="link-1">
        <span class="span-1">1&nbsp;</span>
        Hello
    </a>    
</div>

Css: CSS:

.link-1 {
    font-size: 16px;
    text-decoration: none;
}
.link-1:hover {
    text-decoration: underline;
}
.span-1 {
    font-size: 12px;
}

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM