简体   繁体   English

如何使悬停背景颜色填充链接的高度?

[英]How do I make the hover background color fill the height of the link?

How do I make the hover background-color fill the entire height of the navigation bar plus the padding of the text instead of only the text. 如何使悬停background-color填充导航栏的整个高度,加上文本的填充而不是仅填充文本。

I want to make it look like this. 我要使它看起来像这样。

导航栏

Fiddle 小提琴

What am I missing? 我想念什么? Thank you in advance! 先感谢您!

Here you go. 干得好。 I've created a jsfiddle for you. 我为您创建了一个jsfiddle。 Its working good: 它的工作良好:

http://jsfiddle.net/cRjF4/3/ http://jsfiddle.net/cRjF4/3/

Updated CSS: 更新的CSS:

<style>
.fa {
    font-size: 15px;
    margin-top: -10px;
    margin-bottom: -10px;
}

.navbar-height {
    height: 65px;
}

.clearboth {
    clear: both;
}

/* workbar styles */

.fixed-top {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    background: #FFF;
    text-align: center;
    height: 67px;
    margin: 0 auto;
    width: 100%;
}

.workbar {
    text-align: center;
    margin: 0 auto;
    background-color: #ffe6e6;
}

.worknav {
    list-style: none;
    padding-left: 0px;
    margin: 0 auto;
    text-align: center;
}

.worknav> li {
    text-align: center;
    display: inline-block;
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 11px;
    padding-bottom: 11px;
}

.worknav> li:hover a {
    color: yellow;
}

.worknav>li:hover {
    background-color: black;
}

.worknav > li > a {
    text-decoration: none;
    color: #666;
}

.centered {
    float: none;
    margin-left: auto;
    margin-right: auto;
}

.worktop {
    margin-top: 70px;
}
</style>

If you wish to colour both the padding and the text try something like: 如果您希望同时为填充和文本着色,请尝试如下操作:

a:hover{
background-color:yellow;
color:red;
}

Try to do Anchor link css as 尝试做锚链接CSS作为

.worknav > li > a {    
    text-decoration: none;
    display:inline-block;
    color: #666;
    line-height:65px;



}

Check on http://jsfiddle.net/kka284556/cRjF4/9/ 检查http://jsfiddle.net/kka284556/cRjF4/9/

You can do it by applying padding on anchor tag. 您可以通过在定位标记上应用填充来实现。 Remove height on ul and li tag and instead of height just apply padding on anchor. 移除ul和li标签的高度,而不是高度,只需在锚点上应用填充即可。 And also apply background-color on anchor. 并在锚点上应用背景色。

It will work i think. 我认为这将起作用。 If I am right then let me know i'll share some code if you want. 如果我是正确的,那么让我知道,如果您愿意,我会分享一些代码。

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

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