【问题标题】:How would I add a border-radius to only the start and end of my li navbar?如何仅在 li 导航栏的开头和结尾添加边框半径?
【发布时间】:2013-06-03 18:36:53
【问题描述】:

我正在为我的网站制作一个导航栏,我希望左上角、左下角、右上角和右下角的角是弯曲的。我知道如何使用边界半径,但如果我在导航栏上使用它,它在每个链接上都有一个弯角。我如何在开始和结束时有弯曲的角落? Slightly like these.

这是我的 HTML

<body>

<div id="Wrapper">
    <div id="Header">
        <ul>
            <li><a href=""><img src="Text-Align.png">Home</a></li>
            <li><a href=""><img src="Text-Align.png">Bins</a></li>  
            <li><a href=""><img src="Text-Align.png">Kidzone</a></li>
            <li><a href=""><img src="Text-Align.png">Why?</a></li>
            <li><a href=""><img src="Text-Align.png">How?</a></li>
        </ul>   
    </div>
</div>

</body>

这是我的 CSS

html{
    background-color:#E4E4E4;
}

body,html{
    margin-top: 0px;
    height:100%;
}

#Wrapper{
    display:block;
    background-color: white;
    border-left-style:solid;
    border-left-color:#B8B8B8;
    border-left-width:1px;
    border-right-style:solid;
    border-right-color:#B8B8B8;
    border-right-width:1px;
    width: 800px;
    height: 100%;
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto;
}

#Header{
    width:800px;
    margin-left:35px;
}

#Header ul{
    list-style: none;
    display: inline;
}

#Header li{
    border-left-style:solid;
    border-left-width:1px;  
    border-left-color:white;
    display:block;
    width:145px;
    text-align:center;
    float: left;
}


a:link,a:visited{
    display:block;
    height:30px;
    background-image:url("navbar.gif");
    background-repeat:repeat-x;
    font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
    text-decoration:none;
    font-size:18px;
    color:white;
}

a:hover,a:active{
    background-image:url("navbarhover.gif");
    background-repeat:repeat-x;
}

提前致谢

【问题讨论】:

  • 这里根本没有使用border-radius。我们是否应该猜测“我在导航栏上使用它”是什么意思?
  • 您可以通过使用:first-child:last-child(仅匹配第一个和最后一个元素)伪选择器来实现这一点,但这些在IE
  • 您是否尝试在 ul 级别而不是 li 级别上使用边框半径?喜欢#Header ul{ list-style: none; display: inline; border-radius:10px; }
  • @JohannesKlauß:实际上:first-child 受 IE 7 + 支持

标签: html css


【解决方案1】:

如果您可以使用 CSS3,那么您可以使用 firstlast 伪选择器。

#Header ul li:first-child {

}

#Header ul li:last-child {

}

【讨论】:

    【解决方案2】:

    用这个在你的样式中创建一个 id 标签:

    border-top-left-radius: Xpx;
    border-bottom-left-radius: Xpx;
    

    定义,并定义你想要的li上的id,所以顶部和底部的,并将Xpx更改为你想要的

    【讨论】:

      【解决方案3】:

      为什么不在 UL 上使用边界半径? http://jsfiddle.net/GCyrillus/vwwLb/1/

      #Header ul {
          list-style: none;/* this to wrap floatting elements */
          display: inline-block;
          background:blue linear-gradient(0deg,transparent,#eee,transparent);
          padding:0 2em;
          margin:0;
          border-radius:1em;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-05-28
        • 2018-01-23
        • 1970-01-01
        • 2020-03-02
        • 2022-12-11
        • 1970-01-01
        • 2011-05-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多