简体   繁体   English

背景(a)与边框(ul)之间的空白

[英]White Gap between Background (a) and Border (ul)

I build a Navigationbar, when you hover or clicked a item the background Color of the selected Item will change. 我构建了一个导航栏,当您将鼠标悬停或单击某个项目时,所选项目的背景颜色将发生变化。

At the end I wanted to round up the corners. 最后,我想四舍五入。 Then I saw that there is a white Space which im unable to remove. 然后我看到有一个空白,我无法删除。

HTML 的HTML

    <nav id="nav">
        <ul>
            <li><a href="#home">Home</a></li>
            <li><a href="#lorem">Lorem</a></li>
            <li><a href="#ipsum">Ipsum</a></li>
            <li><a href="#dolor">Dolor</a></li>
        </ul>
    </nav>

CSS 的CSS

#nav
{
    position: absolute;
    top: 50px;
    width: 100%;
}
    #nav > ul
    {
        padding: 0;
        margin: auto;
        width: 50%;

        list-style: none;
        display: flex;

        border: 1px solid #673ab7;
        border-radius: 20px;
        background: #ffffff;
    }
        #nav ul > li 
        {
            margin: 0;
            width: 100%;
            color: #673ab7;

            line-height: 40px;
        }
            #nav ul > li > a
            {
                display: block;
                color: inherit;

                text-align: center;
                text-decoration: none;
                text-transform: uppercase;
                letter-spacing: 2px;

                transition: background 0.25s;

                position: relative;
            }
                #nav ul > li > a:hover
                {
                    background: #ede7f6;
                }
                #nav ul > li:first-child > a:hover
                {
                    border-radius:  20px 0px 0px 20px;
                }



            #nav ul > li.active > a
            {
                border-radius:  20px 0px 0px 20px;
                color: #FFFFFF;
                background: #673ab7;
            }

JS JS

$(document).ready(function()
{
  $("#nav > ul > li").click(function()
  {
    $("#nav > ul > li").each(function()
    {
        $(this).removeClass("active");
    });
    $(this).addClass("active");
  });
});

Demo: http://jsfiddle.net/sdaq97hh/31/ 演示: http : //jsfiddle.net/sdaq97hh/31/

Please add overflow hidden style in ul tag 请在ul标签中添加溢出隐藏样式

#nav > ul {
padding: 0;
margin: auto;
width: 80%;
list-style: none;
display: flex;
border: 1px solid #673ab7;
border-radius: 20px;
background: #ffffff;
overflow: hidden;
}

You could target the last li , like this: 您可以定位到最后一个li ,如下所示:

#nav ul > li:last-child a {
  border-radius: 0 20px 20px 0px;
}

JSFIDDLE JSFIDDLE

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

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