有趣的CSS形状导航(V形)

时间:2012-01-27 16:40:15

标签: html css shape shapes css-shapes

我正在为网站构建一个相当有趣的导航形状。每个菜单项需要的形状如下所示:

enter image description here

最终导航将看起来像这个扩展版本:

enter image description here

我认为在CSS中执行这些形状将是一个有趣的实验。其中一个箭头形状的CSS和HTML在这里:

    .arrowEndOn {
        font-size: 10px; line-height: 0%; width: 0px;
        border-top: 11px solid #FFFFFF;
        border-bottom: 11px solid #FFFFFF;
        border-left: 5px solid transparent;
        border-right: 5px solid #FFFFFF;    
        float: left;
        cursor: pointer;
    }

    .arrowBulkOn {
        height: 20px;
        background: #FFFFFF;
        padding: 2px 5px 0px 0px;
        float: left;
        color: #000000;
        line-height: 14pt;
        cursor: pointer;
    }

    .arrowStartOn {
        font-size: 0px; line-height: 0%; width: 0px;
        border-top: 11px solid transparent;
        border-bottom: 11px solid transparent;
        border-left: 5px solid #FFFFFF;
        border-right: 0px solid transparent;        
        float: left;
        cursor: pointer;
    }

    <div id="nav" class="navArrow" style="position: relative;">
        <div class="arrowEndOn" id="nav">&nbsp;</div>
        <div class="arrowBulkOn" id="nav">NAV</div>
        <div class="arrowStartOn" id="nav">&nbsp;</div>
    </div>

每个导航项都有一个负偏移应用于它(我已经离开了演示),因为它被渲染以使它们彼此齐平。

我使用Javascript处理翻转和状态。

我的问题是导航器一直延伸到页面的宽度。目前,我必须将导航容器设置为更大的宽度以适应所有情况。

我已尝试将溢出设置为隐藏但最后一项是降低级别而不是继续进行并且只是将结束切断。

我在这里设置了一个例子 - http://jsfiddle.net/spacebeers/S7hzu/1/

红色边框为overflow: hidden;,蓝色边框为{。}

我的问题是:如何让所有的框都浮动在一条填充包含div的宽度的行中,而不会让它们下降到某个级别。

由于

2 个答案:

答案 0 :(得分:1)

为每个箭头添加一个负边距:

.navArrow {
  float: left;
  margin-left: -8px;
}

演示:http://jsfiddle.net/S7hzu/2/

答案 1 :(得分:0)

Flexbox的

您可以使用此示例

https://codepen.io/WBear/pen/pPYrwo

它适用于新浏览器,支持旧版浏览器所需的一些更改。

HTML:

<div class="content">
<div class="as1">
  <a href="#">NAV</a>
  </div>
 <div class="as2">
   <a href="#">NAV</a>
   </div>
  <div class="as3">
   <a href="#">NAV</a>
   </div>
  </div>

CSS:

 .content {
  margin-top: 10px;
  width: 100%;
  display: inline-flex;

}

.as1, .as2, .as3 {
  height: 70px;
  min-width: 8%;
  max-width: 100%;
  background-color: black;
  position: relative;
  display: inline-flex;
  text-align: center;
  flex-wrap: wrap;
  flex-grow: 1;

}

.as1 a, .as2 a, .as3 a {
  text-decoration: none;
  display: inline-flex;
  color: white;
  margin: auto;
  font-size: 14pt;

}

.as1:after {
  content: "";
  position: absolute;
  right: 4px;
  border-top: 35px solid transparent;
  border-left: 25px solid black;
  border-bottom: 35px solid transparent;
  z-index: 2;

}

.as2 {
  background-color: grey;
  margin-left: -29px;


}
.as2:after {
  content: "";
  position: absolute;
  right: 4px;
  border-top: 35px solid transparent;
  border-left: 25px solid grey;
  border-bottom: 35px solid transparent;
  z-index: 3;

}

.as3 {
  background-color: #A9A9A9;
  margin-left: -29px;
}