CSS3步骤菜单全宽度响应箭头

时间:2017-11-20 14:00:32

标签: html css html5 css3

我在桌面上创建了一个带有左右箭头的CSS步骤。在移动设备上,我希望它看起来像这样:

Goal

这是我到目前为止: https://jsfiddle.net/06u3bm72/

如您所见,我想在每个列表项上创建全宽顶部箭头,以便创建三角形形状,就像设计一样。有没有办法保持我目前的标记并实现这一目标?

我的代码是:

.breadcrumbs-two {
  margin: 0;
  padding: 0;
  list-style: none;
}

.breadcrumbs-two {
  overflow: hidden;
  width: 100%;
}

.breadcrumbs-two li {
  float: left;
  width: 18.3%;
}

.breadcrumbs-two a {
  text-transform: uppercase;
  float: left;
  text-decoration: none;
  color: #FFF;
  position: relative;
  text-align: center;
  width: 100%;
  height: 80px;
  line-height: 1.3;
  font-size: 15px;
}

.breadcrumbs-two a span {
  display: inline-block;
  max-width: 100%;
  width: 150px;
  margin: auto;
  position: relative;
  top: 20px;
}

.breadcrumbs-two a::before {
  content: "";
  position: absolute;
  top: 50%;
  margin-top: -40px;
  border-width: 40px 0 40px 30px;
  border-style: solid;
  border-color: #ddd #ddd #ddd transparent;
  left: -30px;
}

.breadcrumbs-two a::after {
  content: "";
  position: absolute;
  top: 50%;
  margin-top: -40px;
  border-top: 40px solid transparent;
  border-bottom: 40px solid transparent;
  border-left: 30px solid #ddd;
  right: -30px;
}

.bread1 a {
  background-color: #8ac43c;
}

.bread1 a::before {
  border-color: #8ac43c #8ac43c #8ac43c transparent;
}

.bread1 a::after {
  border-color: transparent #8ac43c transparent #8ac43c;
}

.bread2 a {
  background-color: #69aa4e;
}

.bread2 a::before {
  border-color: #69aa4e #69aa4e #69aa4e transparent;
}

.bread2 a::after {
  border-color: transparent #69aa4e transparent #69aa4e;
}

.bread3 a {
  background-color: #448e60;
}

.bread3 a::before {
  border-color: #448e60 #448e60 #448e60 transparent;
}

.bread3 a::after {
  border-color: transparent #448e60 transparent #448e60;
}

.bread4 a {
  background-color: #1f7171;
}

.bread4 a::before {
  border-color: #1f7171 #1f7171 #1f7171 transparent;
}

.bread4 a::after {
  border-color: transparent #1f7171 transparent #1f7171;
}

.bread5 a {
  background-color: #005581;
}

.bread5 a::before {
  border-color: #005581 #005581 #005581 transparent;
}

.bread5 a::after {
  border-color: transparent #005581 transparent #005581;
}

@media screen and (max-width: 991px) {
  .breadcrumbs-two li {
    float: none;
    width: 100%;
  }
  .breadcrumbs-two a {
    width: 100%;
  }
  li.bread1 {
    margin-left: 0;
  }
  .breadcrumbs-two a {
    padding-top: 0;
    background-clip: content-box;
    overflow: hidden;
  }
  .breadcrumbs-two a::before {
    content: "";
    position: absolute;
    top: 50%;
    margin-top: -40px;
    border-width: 40px 0 40px 20px;
    border-width: 40px 0px 0px 40px;
    border-style: solid;
    left: 50%;
    width: 100%;
    left: 0;
    border: 0;
    z-index: 10;
    height: 10px;
    top: 0;
    margin: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 20px auto 0 auto;
    border-color: #007bff transparent transparent transparent;
    display: none;
  }
  .breadcrumbs-two a::after {
    content: "";
    position: absolute;
    top: 50%;
    margin-top: -40px;
    right: -20px;
    display: none;
  }
}
<ul class="breadcrumbs-two">
  <li class="bread1"><a><span><strong>Discovery</strong> and sales audit</span></a></li>
  <li class="bread2"><a><span>Priorities and <strong>Action Plan</strong></span></a></li>
  <li class="bread3"><a><span>Workshops and <strong>Collaborations</strong></span></a></li>
  <li class="bread4"><a><span><strong>Execute</strong> and <strong>Implement</strong></span></a></li>
  <li class="bread5"><a><span><strong>Results</strong> and <strong>Adoption</strong></span></a></li>
</ul>

3 个答案:

答案 0 :(得分:1)

先检查browser support

还有其他方法可以做到这一点(也许是背景图片吗?)但是我用新技术做到了:clip-path

有一些硬编码的数字取决于每个菜单项的高度(请查看下面代码的注释)

我也更改了您的代码,但随时可以阅读并根据您的需要进行修改。

要获取我使用的剪辑路径代码bennettfeely.com/clippy

.breadcrumbs-two {
  padding: 0;
  padding-bottom: 20px; /* hardcoded - (height * 0.25) */
  margin: 0;
  width: 18.3%;
  list-style: none;
  overflow: hidden;
}

.breadcrumbs-two li {
  display: block;
}

.breadcrumbs-two a {
  display: block;
  width: 100%;
  height: 80px; /* this is where the height comes from */
  margin-bottom: -20px; /* hardcoded - (height * 0.25) - you can add +1px to hide some "white broder" that may showup between menu items */
  color: #FFF;
  font-size: 15px;
  text-align: center;
  text-transform: uppercase;
  text-decoration: none;
  clip-path: polygon(0 0, 0 75%, 50% 100%, 100% 75%, 100% 0, 50% 25%); /* this is where the 0.25 comes from */
}
.breadcrumbs-two a:before {
    content: "";
    display: inline-block;
    vertical-align: middle;
    height: 100%;
}

.breadcrumbs-two a span {
  box-sizing: border-box;
  display: inline-block;
  width: 100%;
  max-width: 170px;
  margin-top: 10px; /* hardcoded - ((height * 0.25) / 2) */
  vertical-align: middle;
}

.bread1 a {
  background-color: #8ac43c;
}
.bread2 a {
  background-color: #69aa4e;
}
.bread3 a {
  background-color: #448e60;
}
.bread4 a {
  background-color: #1f7171;
}
.bread5 a {
  background-color: #005581;
}


@media screen and (max-width: 991px) {
  .breadcrumbs-two {
    width: 100%;
  }
}
<div class="container">
  <ul class="breadcrumbs-two">
    <li class="bread1">
      <a><span><strong>Discovery</strong> and sales audit</span></a>
    </li>
    <li class="bread2">
      <a><span>Priorities and <strong>Action Plan</strong></span></a>
    </li>
    <li class="bread3">
      <a><span>Workshops and <strong>Collaborations</strong></span></a>
    </li>
    <li class="bread4">
      <a><span><strong>Execute</strong> and <strong>Implement</strong></span></a>
    </li>
    <li class="bread5">
      <a><span><strong>Results</strong> and <strong>Adoption</strong></span></a>
    </li>
  </ul>
</div>

答案 1 :(得分:1)

我用transform: skewY(6deg)或-6deg计算出来,在标记之前和之后创建两个50%-width div,将其左右放置到a标记。

https://jsfiddle.net/06u3bm72/1/

浏览器support就在这里。

您只需更新height: 50%;width:100%以及transform: skewX(xdeg)top/bottom: 0即可修复桌面版。 94%的浏览器完全支持这一点。

&#13;
&#13;
.breadcrumbs-two{
		  margin: 0;
		  padding: 0;
		  list-style: none;
		}
		.breadcrumbs-two{
		  overflow: hidden;
		  width: 100%;
		}
    .breadcrumbs-two li{
		  float: left;
		  width: 18.3%;
		}
		.breadcrumbs-two a{
		  text-transform: uppercase;
		  float: left;
		  text-decoration: none;
		  color: #FFF;
		  position: relative;
		  text-align: center;
		  width: 100%;
		  height: 80px;
		  line-height: 1.3;
	    font-size: 15px;
		}   
		.breadcrumbs-two a span {
			display: inline-block;
			max-width: 100%;
			width: 150px;
			margin: auto;
			position: relative;
			top: 20px;
		}
		.breadcrumbs-two a::before{
		  content: "";
		  position: absolute;
		  top: 50%; 
		  margin-top: -40px;   
		  border-width: 40px 0 40px 30px;
		  border-style: solid;
		  border-color: #ddd #ddd #ddd transparent;
		  left: -30px;
		}
		.breadcrumbs-two a::after{
		  content: "";
		  position: absolute;
		  top: 50%; 
		  margin-top: -40px;   
		  border-top: 40px solid transparent;
		  border-bottom: 40px solid transparent;
		  border-left: 30px solid #ddd;
		  right: -30px;
		}
		.bread1 a {
			background-color: #8ac43c;
		}
		.bread1 a::before {
			border-color: #8ac43c #8ac43c #8ac43c transparent;
		}
		.bread1 a::after {
			border-color: transparent #8ac43c transparent #8ac43c;
		}
		.bread2 a {
			background-color: #69aa4e;
		}
		.bread2 a::before {
			border-color: #69aa4e #69aa4e #69aa4e transparent;
		}
		.bread2 a::after {
			border-color: transparent #69aa4e transparent #69aa4e;
		}
		.bread3 a {
			background-color: #448e60;
		}
		.bread3 a::before {
			border-color: #448e60 #448e60 #448e60 transparent;
		}
		.bread3 a::after {
			border-color: transparent #448e60 transparent #448e60;
		}
		.bread4 a {
			background-color: #1f7171;
		}
		.bread4 a::before {
			border-color: #1f7171 #1f7171 #1f7171 transparent;
		}
		.bread4 a::after {
			border-color: transparent #1f7171 transparent #1f7171;
		}
		.bread5 a {
			background-color: #005581;
		}
		.bread5 a::before {
			border-color: #005581 #005581 #005581 transparent;
		}
		.bread5 a::after {
			border-color: transparent #005581 transparent #005581;
		}
	    
		@media screen and (max-width: 991px) {
      .breadcrumbs-two {
        padding-top: 40px;
      }
      .breadcrumbs-two li {
        float: none;
        width: 100%;
      }
			.breadcrumbs-two a {
			  position: relative;
			  width: 100%;	
        background-color: transparent;
        overflow: visible;
			}
      .breadcrumbs-two a span {
        z-index: 1;
        position: absolute;
        top: 15%;
        width: 150px;
        left: 50%;
        margin-left: -75px;
			}
      
			.breadcrumbs-two  a::before {
        width: 50%;
        height: 100%;
        position: absolute;
        left: 0;
        background-color: #8ac43c;
        border: 0;
        transform: skewY(6deg);
        top: 30%;
      }
			.breadcrumbs-two  a::after {
        width: 50%;
        height: 100%;
        position: absolute;
        right: 0;
        background-color: #8ac43c;
        border: 0;
        transform: skewY(-6deg);
        top: 30%;
      }
      .breadcrumbs-two .bread1 a::after, .breadcrumbs-two .bread1 a::before {
        background-color: #8ac43c;
      }
      .breadcrumbs-two .bread2 a::after, .breadcrumbs-two .bread2 a::before {
        background-color: #69aa4e;
      }
      .breadcrumbs-two .bread3 a::after, .breadcrumbs-two .bread3 a::before {
        background-color: #448e60;
      }
      .breadcrumbs-two .bread4 a::after, .breadcrumbs-two .bread4 a::before {
        background-color: #1f7171;
      }
      .breadcrumbs-two .bread5 a::after, .breadcrumbs-two .bread5 a::before {
        background-color: #005581;
      }
			/* li.bread1 {
			  margin-left: 0;
			}
			.breadcrumbs-two a {
			  padding-top:0;
			  background-clip:content-box;
			  overflow:hidden;
			}
			.breadcrumbs-two a::before{
			  content: "";
			  position: absolute;
			  top: 50%; 
			  margin-top: -40px;   
			  border-width: 40px 0 40px 20px;
			  border-width: 40px 0px 0px 40px;
			  border-style: solid;
			  left: 50%;
			  width: 100%;
			  left: 0;
			  border: 0;
			  z-index: 10;
			  height: 10px;
			  top: 0;
			  margin: 0;
			  width: 0;
			height: 0;
			border-style: solid;
			border-width: 20px auto 0 auto;
			border-color: #007bff transparent transparent transparent;
			display: none;
			}
			.breadcrumbs-two a::after{
			  content: "";
			  position: absolute;
			  top: 50%; 
			  margin-top: -40px;   
			  right: -20px;
			  display: none;
			}
			 */
		}
&#13;
<div class="container" style="width: 1040px; max-width: 100%; margin: auto;">
<ul class="breadcrumbs-two">
    <li class="bread1"><a><span><strong>Discovery</strong> and sales audit</span></a></li>
    <li class="bread2"><a><span>Priorities and <strong>Action Plan</strong></span></a></li>
    <li class="bread3"><a><span>Workshops and <strong>Collaborations</strong></span></a></li>
    <li class="bread4"><a><span><strong>Execute</strong> and <strong>Implement</strong></span></a></li>
    <li class="bread5"><a><span><strong>Results</strong> and <strong>Adoption</strong></span></a></li>
</ul>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

你可以使用伪元素之前和之后以及透明色的边框来实现它。

以下是如何操作的示例,可以更好地进行优化,但我认为它可以为您提供指导。

https://codepen.io/itscarlosisaac/pen/MOQOZO

.breadcrumbs-two{
      margin: 0;
      padding: 0;
      list-style: none;
    }
    .breadcrumbs-two{
      overflow: hidden;
      width: 100%;
    }
.breadcrumbs-two li{
      float: left;
      width: 18.3%;
    }
    .breadcrumbs-two a{
      text-transform: uppercase;
      float: left;
      text-decoration: none;
      color: #FFF;
      position: relative;
      text-align: center;
      width: 100%;
      height: 80px;
      line-height: 1.3;
    font-size: 15px;
    }   
    .breadcrumbs-two a span {
        display: inline-block;
        max-width: 100%;
        width: 150px;
        margin: auto;
        position: relative;
        top: 20px;
    }
    .breadcrumbs-two a::before{
      content: "";
      position: absolute;
      top: 50%; 
      margin-top: -40px;   
      border-width: 40px 0 40px 30px;
      border-style: solid;
      border-color: #ddd #ddd #ddd transparent;
      left: -30px;
    }
    .breadcrumbs-two a::after{
      content: "";
      position: absolute;
      top: 50%; 
      margin-top: -40px;   
      border-top: 40px solid transparent;
      border-bottom: 40px solid transparent;
      border-left: 30px solid #ddd;
      right: -30px;
    }
    .bread1 a {
        background-color: #8ac43c;
    }
    .bread1 a::before {
        border-color: #8ac43c #8ac43c #8ac43c transparent;
    }
    .bread1 a::after {
        border-color: transparent #8ac43c transparent #8ac43c;
    }
    .bread2 a {
        background-color: #69aa4e;
    }
    .bread2 a::before {
        border-color: #69aa4e #69aa4e #69aa4e transparent;
    }
    .bread2 a::after {
        border-color: transparent #69aa4e transparent #69aa4e;
    }
    .bread3 a {
        background-color: #448e60;
    }
    .bread3 a::before {
        border-color: #448e60 #448e60 #448e60 transparent;
    }
    .bread3 a::after {
        border-color: transparent #448e60 transparent #448e60;
    }
    .bread4 a {
        background-color: #1f7171;
    }
    .bread4 a::before {
        border-color: #1f7171 #1f7171 #1f7171 transparent;
    }
    .bread4 a::after {
        border-color: transparent #1f7171 transparent #1f7171;
    }
    .bread5 a {
        background-color: #005581;
    }
    .bread5 a::before {
        border-color: #005581 #005581 #005581 transparent;
    }
    .bread5 a::after {
        border-color: transparent #005581 transparent #005581;
    }

    @media screen and (max-width: 991px) {
  .breadcrumbs-two{
    overflow-x:hidden;
    overflow-y:visible;
    padding-bottom:40px;
  }
  .breadcrumbs-two a span{ top:45px; }
        .breadcrumbs-two li {
            float: none;
            width: 100vw;
    height: 80px;
    position:relative;
    display:block;
    overflow:visible;
        }
  .breadcrumbs-two li:first-child:before{
    content:'';
    display:block;
    width: 100vw;
    height:30px;
    position:absolute;
    top:0;
    left:0;
    right:0;
    margin:auto;
    border-top:30px solid white;
    border-left:50vw solid transparent;
    border-right:50vw solid transparent;
    box-sizing:border-box;
    z-index:1;
  }
  .breadcrumbs-two li:after{
    content:'';
    display:block;
    width: 100vw;
    height:30px;
    position:absolute;
    bottom:-30px;
    left:0;
    right:0;
    margin:auto;
    border-left:50vw solid transparent;
    border-right:50vw solid transparent;
    box-sizing:border-box;
  }
        .breadcrumbs-two a {
            width: 100%;    
        }
        li.bread1 {
    z-index:10;
        }
        li.bread2 {
    z-index:9;
        }
        li.bread3 {
    z-index:8;
        }
        li.bread4 {
    z-index:7;
        }
        li.bread5 {
    z-index:6;
        }
  li.bread1:after{
    border-top:30px solid #8ac43c;
  }
  li.bread2:after{
    border-top:30px solid #69aa4e;
  }
  li.bread3:after{
    border-top:30px solid #448e60;
  }
  li.bread4:after{
    border-top:30px solid #1f7171;
  }
  li.bread5:after{
    border-top:30px solid #005581;
  }

    }
相关问题