外容器上的CSS边框半径

时间:2014-11-07 15:25:06

标签: html css twitter-bootstrap-3 navbar

我对一些css边界半径有点问题。

我正在使用带有.navbar-nav等的Bootstrap 3,我需要容器有一个像导航按钮一样的边框半径,但我不知道从哪里开始。如果有人能指出我正确的方向,请万分感谢!提前致谢

enter image description here

正如你所看到的那样,外面的部分是方形的,但我需要它像导航按钮一样圆润。

我想要的是:

enter image description here

以下是代码:

 <div class="navbar navbar-default" role="navigation">
  <div class="container">
    <div class="row">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Who we are</a></li>
          <li><a href="#">What we do</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
              <li><a href="#">Design</a></li>
              <li><a href="#">Construction</a></li>
              <li><a href="#">Planned maintenance</a></li>
            </ul>
          </li>
          <li><a href="#">Projects</a></li>
          <li><a href="#">Our responsibilities</a></li>
          <li><a href="#">Contact us</a></li>
        </ul>
      </div><!--/.nav-collapse -->
    </div>
  </div>
</div>

和CSS

.navbar-collapse {
  padding-right: 15px;
  padding-left: 15px;
}
.navbar-default {
  background-color: #ff6b00;
  border-color: transparent;
  border-radius: 0;
  margin-bottom:0;
  border:0;
}
.navbar-default .navbar-nav {
  background:#092c74;
}
.navbar-default .navbar-nav > li > a {
  color: #FFF;
  background:#ff6b00;
  padding-left:20.9px;
  padding-right:20.8px;
  margin:0 1.5px;
  text-transform: uppercase;
  -webkit-border-top-left-radius: 5px;
  -webkit-border-top-right-radius: 5px;
  -moz-border-radius-topleft: 5px;
  -moz-border-radius-topright: 5px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  transition: all .2s linear;
  -webkit-transition: all .1s linear;
  -moz-transition: all .1s linear;
  -o-transition: all .1s linear;
}
.navbar-default .navbar-nav > li:first-child a {
  margin-left:3px;
}
.navbar-default .navbar-nav > li:last-child a {
  margin-right:3px;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
  color: #FFF;
  background-color: #c85400;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
  color: #092c74;
  background-color: #FFF;
}

1 个答案:

答案 0 :(得分:0)

欢呼帮助我设法解决了问题。使用:before:after

.navbar-default .navbar-nav:before {
  width:5px;
  height:5px;
  position:absolute;
  top:0;
  left:10px;
  background:#ff6b00;
  background-image:url('../images/top-right-radius.png');
  background-position: top right;
  background-repeat: no-repeat;
}
.navbar-default .navbar-nav:after {
  width:5px;
  height:5px;
  position:absolute;
  top:0;
  right:10px;
  background:#ff6b00;
  background-image:url('../images/top-left-radius.png');
  background-position: top right;
  background-repeat: no-repeat;
}
@media only screen and (max-width: 767px) { .navbar-default .navbar-nav:before { display:none; } .navbar-default .navbar-nav:after { display:none; } }

看起来丑陋但仍在工作,很想知道是否有更好的方法来做到这一点。再次感谢大家的帮助,非常感谢!