如何创建Curved& CSS中重叠的菜单选项卡

时间:2014-09-07 17:26:09

标签: html css menu border css-shapes

我想制作一个菜单,其中菜单的两端重叠,它们有弯曲的边框和略微倾斜的边缘。

不使用背景图像,是否可以只用CSS做这样的菜单?

为了更好地理解,请附上下面的菜单示例。想知道如何使用CSS单独将部件标记为红色。

enter image description here

请提前帮助,谢谢。

2 个答案:

答案 0 :(得分:14)

Curved UL LI list tabs

  • 歪斜:before:after伪元素,
  • 将pseudos设置为某个-偏移量
  • 将左上角border-radius添加到:before,将右上角添加到:after
  • 如果需要(删除顶部硬边)将顶部边框半径添加到A元素
  • z-index:1;添加到:after
  • z-index:1;添加到 .active :before元素。



nav li {
  display: inline-block;
  border-bottom: 1px solid #8BBF50;
  margin-left: -20px;
}

nav a {
  text-decoration: none;
  color: #fff;
  background: #8BBF50;
  position: relative;
  display: inline-block;
  margin: 0 22px;
  padding: 8px 11px;
  text-shadow: 0 1px 0 rgba(0, 2, 0, 0.4);
  border-radius: 7px 7px 0 0; /* just to smooth the top edges */
}

nav a:before,
nav a:after {
  content: " ";
  position: absolute;
  top: 0;
  width: 23px;
  height: 100%;
  background-color: inherit;
}

nav a:before {
  border-radius: 12px 0 0 0;
  transform: skew(-24deg);
  left: -13px; /* play with this one to give the LI border ~2px extrusion */
}

nav a:after {
  border-radius: 0 12px 0 0;
  transform: skew(24deg);
  right: -13px; /* play with this one to give the LI border ~2px extrusion */
  border-right: 1px solid #628E2F;
  z-index: 1; /* overlap next element */
}


/* LI ACTIVE  */

nav li.active {
  border-bottom: 1px solid #fff;
}

nav li.active a {
  color: #8BBF50;
  background: #fff;
}

nav li.active a:before {
  z-index: 1; /* overlap prev element */
}

nav li.active a:after {
  border-bottom: 1px solid #fff;
}

<nav>
  <ul>
    <li><a>Home</a></li>
    <li class="active"><a>About</a></li>
    <li><a>Products</a></li>
    <li><a>Map</a></li>
    <li><a>Contact</a></li>
  </ul>
</nav>
&#13;
&#13;
&#13;

上面没有提供标签底部的凹曲率,而是使用LI元素边框底部2px挤出来给眼睛带来轻微的感觉。不完美,但仍然是一个很好的解决方案。

Curved list tabs - detail

live demo on jsBin

答案 1 :(得分:1)

我想我已经解决了它。

DEMO

以下是我在“http://css-tricks.com/tabs-with-round-out-borders/

中提供的”准则“中添加的内容

我刚刚将background-color属性添加到:before :after css的伪元素.activeli。< / p>

如下:

.tabs li { 
  /* Makes a horizontal row */
  float: left; 

  /* So the psueudo elements can be
     abs. positioned inside */
  position: relative; 
  /*Make Sure The Li's stays Inline */
   display:inline-block;
  /* Remove Ugly Chromes `.` */
   list-styling:none;
}
.tabs .active a { 
  /* Colors when tab is active */
  background: #aea; /* Added Green Color */ 
  color: black; 
}
.tabs li:last-child:after,   .tabs li:last-child a:after,
.tabs li:first-child:before, .tabs li:first-child a:before,
.tabs .active:after,   .tabs .active:before, 
.tabs .active a:after, .tabs .active a:before {
    content: "";
    background: #afa; 
  }
.tabs .active:before, .tabs .active:after {
  background: white; 
  background:#afa;  
  /* Squares below circles */
  z-index: 1;
}
.tabs .active a:after, .tabs .active a:before {
  background: #ddc385;
}

,在添加一些JQuery以使其生效之后,这是另一个fiddle。 希望它有所帮助:)。