简体   繁体   English

当显示li时,用锚填充li:inline

[英]Filling li with anchor when li is display:inline

After about 15/20 minuets of research and googling I have not found a solution. 经过大约15/20的研究和谷歌搜索,我还没有找到解决方案。

I am trying to fill a list item with an anchor however the li is set to display inline code: 我试图用锚填充列表项,但是li设置为显示内联代码:

#nav{
    font-family:"chaparral-pro", Georgia, "Times New Roman", serif;
    position: relative;
    background-color: #404041;
    width: 100%;
    height: 40px;
    text-align: center;
    font-size: 15px;
    margin-top: -15px;
}

#nav a{
    color: #f9a13e;
    text-decoration: none;
}

#nav a{
    display: inline-block;
    height: 100%
}

#nav a:hover{
    color: #fff;
    text-decoration: none;
}


ul#navInner{
    position: relative;
    text-align: left;
    width: 840px;
    margin: 0 auto;
    height: 40px;
    padding-top: 10px;
}

ul#navInner li{
    display: inline;
    border-right: 1px solid white;
    height: 40px;
    padding: 11px 8px 16px 8px;
}

li.noBorderR{
    border: none !important;
}

HTML: HTML:

<div id="nav">
  <ul id="navInner">
    <li><a href="_#">Home</a></li>
    <li><a href="_#">About Us</a></li>
    <li><a href="_#">Our People</a></li>
    <li><a href="_#">How can we help</a></li>
    <li><a href="_#">Newsroom</a></li>
    <li><a href="_#">Resources</a></li>
    <li><a href="_#">Careers</a></li>
    <li><a href="_#">Contact Us</a></li>
    <li class="noBorderR"><a href="_#">Text Size</a></li>
  </ul>
</div><!-- end nav -->

Sorry for posting such a basic question on here! 很抱歉在这里发布这样的基本问题! I cannot figure this one out! 我无法弄清楚这一点!

If I set the a{} to display: block it puts the whole li on block, and inline-block does nothing. 如果我将a {}设置为display:block,则会将整个li放在block上,而inline-block则不执行任何操作。

您可以仅使用上的填充和高度/宽度来填充所需的空间吗?

如何将高度和宽度应用于<a>标记,并将CSS中的line-height设置为列表项的高度?

Rather than setting the padding and the height on the li, set these on the a and set it to display block. 与其在li上设置填充和高度,不如在a上设置它们并将其设置为display block。 Then set the line-height to the same as the a height and the text will align in the middle vertically. 然后将line-height设置为与a高度相同的值,文本将垂直居中对齐。

If you then want the links to appear horizontally, float the li left. 如果您然后希望链接水平显示,请向左浮动li。 I always find when styling navigation it is best to start with the innermost element and work out. 我总是发现,在对导航进行样式设置时,最好从最里面的元素开始并进行计算。

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

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