首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >菜单项之间不需要的透明空格(边框不起作用)

菜单项之间不需要的透明空格(边框不起作用)
EN

Stack Overflow用户
提问于 2018-06-08 03:13:59
回答 1查看 24关注 0票数 0

这是我从CSS Tricks.上得到的一个纯CSS导航栏,我绞尽脑汁试图找出是什么造成了下拉菜单上每一项下面的空白,打开,透明的空间,检查了每一个CSS属性,但我无法得到它。你可以通过它们看到图像滑块,这不是我们想要的。有人能帮上忙吗?

它比fiddle中的on the web更明显。

下面是HTML:

代码语言:javascript
复制
<nav>
    <ul class="nav"> <!-- Menu from https://css-tricks.com/targetting-menu-elements-submenus-navigation-bar/ -->
        <li><a href="http://www.neoadvent.tech/">Home</a></li>
        <li><a href="../services/index.html">Services</a>
            <ul class="align-left">
                <li><a href="../services/drug-formulation-services.html">Drug Formulation</a></li>
                <li><a href="../services/analytical-and-bioanalytical-services.html">Analytical & Bioanalytical Services</a></li>
                <li><a href="../services/thermal-analysis-by-tga-and-dsc-services.html">Thermal Analysis</a></li>
                <li><a href="../services/custom-synthesis-services.html">Custom Synthesis</a></li>
                <li><a href="../services/pharmacology-and-toxicology-services.html">Pharmacology & Toxicology</a></li>
                <li><a href="../services/regulatory-support-for-fda-filings-for–drugs-and–medical devices-services.html">Regulatory Support for Drugs & Medical Devices</a></li>
                <li><a href="../services/materials-testing-services.html">Materials Testing</a></li>
                <li><a href="../pdfs/catalog_of_chemical_reagents_and_materials.pdf">Catalog of Chemical Reagents & Materials</a></li>
                <li><a href="../services/food-analysis-for-safety-services.html">Food Analysis</a></li>
            </ul>
        </li>
        <li><a href="#">Technologies</a>
            <ul class="align-left">
                <li><a href="../technologies/api-micronization.html">API Micronization</a></li>
                <li><a href="#">Drug Delivery</a>
                    <ul class="align-left">
                        <li><a href="../technologies/drug-delivery/sol-gel-encapsulation.html">Sol-gel Encapsulation</a></li>
                        <li><a href="../technologies/drug-delivery/smart-hydrogels-and-biomaterials.html">Smart Hydrogels and Biomaterials</a></li>
                        <li><a href="../technologies/drug-delivery/electrorheologically-controlled-drug-release.html">Electrorheologically-Controlled Drug Release</a></li>
                        <li><a href="../technologies/drug-delivery/polyphosphazenes.html">Polyphosphazenes</a></li>
                    </ul>
                <li><a href="#">Materials Science</a>
                    <ul class="align-left">
                    <li><a href="../technologies/materials-science/coatings.html">Coatings</a></li>
                    <li><a href="../technologies/materials-science/structural-materials.html">Structural Materials</a></li>
                    <li><a href="../technologies/materials-science/viscosity-control-in-non-aqueous-systems.html">Viscosity Control: Non-aqueous Systems</a></li>
                    </ul>
                </li>
            </ul>
        </li>
        <li><a href="../services/api-storage.html">Bio-Pharma Storage</a></li>
        <li><a href="../about-us/index.html">About Us</a></li>
        <li><a href="../news/index.html">News</a></li>
        <li><a href="../about-us/contact.html">Contact</a></li>
    </ul>
</nav>

和CSS:

代码语言:javascript
复制
nav {
    display: block;
    width:100%;
    text-align: center;
}
nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.nav a {
    display: block;
    background-color: #003399;
    color: white;
    text-decoration: none;
    padding: .5em 1.4em .7em;
    font-size: 75%;
    letter-spacing: 1px;
    position: relative;
}
.nav {
    vertical-align: top;
    display: inline-block;
    border-radius: 6px;
}
.nav li { position: relative; }
.nav > li {
    float: left;
    border-bottom: 4px #aaa solid;
    margin-right: 1px;
}
.nav > li > a {
    margin-bottom: 1px;
}
.nav > li:hover, .nav > li:hover >a { border-bottom-color: #99ddff; }
.nav li:hover > a { color: #99ddff; }
.nav > li:first-child { border-radius: 4px 0 0 4px; }
.nav > li:first-child>a { border-radius: 4px 0 0 0; }
.nav > li:last-child {
    border-radius: 0 0 4px 0;
    margin-right: 0;
}
.nav > li:last-child >a { border-radius: 0 4px 0 0; }
.nav li li a { margin-top: 1px }
.nav li a:first-child:nth-last-child(2):before {
    content: "";
    position: absolute;
    height: 0;
    width: 0;
    border: 5px solid transparent;
    top: 50%;
    right: 5px;
}

/* submenu positioning*/
.nav ul {
    position: absolute;
    white-space: nowrap;
    border-bottom: 5px solid #99ddff;
    z-index: 1;
    left: -99999em;
}
.nav > li:hover > ul {
    left: auto;
    padding-top: 5px;
    min-width: 100%;
}
.nav > li li ul { border-left: 1px solid #fff; }
.nav > li li:hover > ul {
    /* margin-left: 1px */
    left: 100%;
    top: -1px;
}

/* arrow hover styling */
.nav > li > a:first-child:nth-last-child(2):before { border-top-color: white; }
.nav > li:hover > a:first-child:nth-last-child(2):before {
    border: 5px solid transparent;
    border-bottom-color: orange;
    margin-top: -5px
}
.nav li li > a:first-child:nth-last-child(2):before {
    border-left-color: #aaa;
    margin-top: -5px
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
    border: 5px solid transparent;
    border-right-color: orange;
    right: 10px;
}
.align-left { text-align: left; }
EN

回答 1

Stack Overflow用户

发布于 2018-06-08 03:19:18

代码语言:javascript
复制
.nav > li {
 float: left;
 border-bottom: 4px #aaa solid;
 margin-right: 1px;
}

删除边距-右侧:-)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50748666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档