物品导航设计

时间:2014-11-27 09:23:31

标签: css css3

在尊重每个'li'元素的宽度时,你能帮助我实现导航菜单项目的这种风格吗

设计图片

enter image description here
我的尝试:

 .nav_list ul li a {
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
color: #4d4d4d;
border-right: 2px solid #c79c60;
padding-right: 15px;
margin-right: 15px;
display: inline-block;
height: 12px;
line-height: 11px;
border-bottom: 1px solid orange;
box-sizing: border-box;
}

由于

2 个答案:

答案 0 :(得分:0)

您可以在:hover上向:before:伪元素添加三角形,并使用calc(50% - 5px)5px是三角形的width)将三角形定位在中心。



body {
  background: url(http://s25.postimg.org/b6q25p4p7/black_thread.png) repeat black;
}
.nav-container {
  top: 20px;
  position: relative;
  width: 100%;
  height: 30px;
}
.nav {
  width: 100%;
  height: 30px;
  maring: 0 auto;
  text-align: center;
}
.menu-item {
  display: inline-block;
  width: 67px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  padding-bottom: 10px;
  color: #C79C60;
  position: relative;
}
.menu-item:hover {
  cursor: pointer;
  border-bottom: 2px solid #C79C60;
}
.menu-item:hover:before {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  bottom: 0;
  left: calc(50% - 5px);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 6px solid #C79C60;
}

<body>
  <div class="nav-container">
    <div class="nav">
      <div class="menu-item">HOME</div>
      <div class="menu-item">ABOUT US</div>
      <div class="menu-item">LOCATIONS</div>
      <div class="menu-item">SERVICES</div>
      <div class="menu-item">CONTACT US</div>
    </div>
  </div>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我想使用具有水平自动对齐的绝对定位伪元素。 如果您需要三角形不仅显示在悬停状态,只需从CSS选择器中删除:hover

&#13;
&#13;
.b-link {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  cursor: pointer;
}


.b-nav-item {
  position: relative;
  display: inline-block;
  padding: 10px 20px;
  border-bottom: 2px solid #c59b62;
}
.b-nav-item__label {
  font: 300 1em/1.2 sans-serif;
  text-transform: uppercase;
  text-align: center;
  color: #c59b62;
}
.b-nav-item:hover::before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: 0;
  margin: auto;

  border-right: 4px solid transparent;
  border-bottom: 4px solid #c59b62;
  border-left: 4px solid transparent;
}
&#13;
<div class="b-nav-item">
  <span class="b-nav-item__label">Home</span>
  <a href="#" class="b-link"></a>
</div>
<div class="b-nav-item">
  <span class="b-nav-item__label">Home Sweet Home</span>
  <a href="#" class="b-link"></a>
</div>
&#13;
&#13;
&#13;

您可以在http://codepen.io/kdzuin/pen/JodaQL

找到现场演示