雪佛龙按钮

时间:2017-08-25 06:52:27

标签: html css

我希望用CSS实现这一目标:

enter image description here

这就是我所拥有的:



.breadcrumb {
  list-style: none;
  overflow: hidden;
  font: 18px Helvetica, Arial, Sans-Serif;
  margin: 0;
  padding: 0;
}

.breadcrumb li {
  float: left;
}

.breadcrumb li a {
  border: 1px solid #c00;
  color: black;
  text-decoration: none;
  padding: 10px 0 10px 55px;
  background: #fff;
  position: relative;
  display: block;
  float: left;
}

.breadcrumb li a:after {
  content: " ";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  /* Go big on the size, and let overflow hide */
  border-bottom: 50px solid transparent;
  border-left: 30px solid #fff;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  left: 100%;
  z-index: 2;
}

.breadcrumb li a:before {
  content: " ";
  display: block;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  /* Go big on the size, and let overflow hide */
  border-bottom: 50px solid transparent;
  border-left: 30px solid red;
  position: absolute;
  top: 50%;
  margin-top: -50px;
  margin-left: 1px;
  left: 100%;
  z-index: 1;
}

.breadcrumb li:first-child a {
  padding-left: 10px;
}

.breadcrumb li a:hover {
  background: hsla(34, 85%, 25%, 1);
}

.breadcrumb li a:hover:after {
  border-left-color: hsla(34, 85%, 25%, 1) !important;
}

.breadcrumb li:last-child a {
  border-right: 1px solid red;
}

.breadcrumb li:last-child a:before {
  border-left: 0 solid transparent;
}

<ul class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Vehicles</a></li>
</ul>
&#13;
&#13;
&#13;

的问题:

  1. 无法正确显示右侧边框
  2. 不能让最后一个元素的右边界正常(不是雪佛龙)
  3. 由于右侧边框,无法使悬停状态正确。

3 个答案:

答案 0 :(得分:4)

这是我的工作jsFiddle

    .breadcrumb {
  list-style: none;
  overflow: hidden;
  font: 18px Helvetica, Arial, Sans-Serif;
  margin: 0;
  padding: 0;
}

.breadcrumb li {
  float: left;
  position: relative;
  background: #fff;
  margin: 0 5px;
}

.breadcrumb li a {
  border: 1px solid #0976a1;
  color: #0976a1;
  text-decoration: none;
  padding: 10px 10px 10px 32px;
  position: relative;
  display: block;
  z-index: 99;
  font-weight: bold;
}
.breadcrumb li:first-child a {
  padding-left: 10px;
  border-right: none;
}

.breadcrumb li:last-child a {
 border-left: none;
}
.breadcrumb li:before, .breadcrumb li:after{
  content: " "; 
  display: block; 
  width: 33px; 
  height: 29px; 
  border-top: 5px solid transparent; 
  border-bottom: 1px solid #0976a1; 
  border-right: 1px solid #0976a1; 
  position: absolute; 
  top: 4px; 
  z-index: -1;
  background: #fff;
  transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);

}
.breadcrumb li:before {
  left: 87%; 
}
.breadcrumb li:after {
  left: 81%;
}
.breadcrumb li:first-child:before, .breadcrumb li:first-child:after{ z-index: 1; }
.breadcrumb li:first-child:after{ left: 73%; }
.breadcrumb li:last-child:before, .breadcrumb li:last-child:after{
  display: none;
}


.breadcrumb li:first-child:hover:after, .breadcrumb li:hover{ background: #0976a1; }
.breadcrumb li:hover a{ border-color: transparent; }
.breadcrumb li:hover a{ color: #fff; }
<ul class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Vehicles</a></li>
</ul>

我希望这会对你有所帮助:)。

答案 1 :(得分:1)

我认为这段代码很有帮助。

&#13;
&#13;
.breadcrumb {
  list-style: none;
  overflow: hidden;
  font: 18px Helvetica, Arial, Sans-Serif;
  margin: 0;
  padding: 0;
}

.breadcrumb li {
  float: left;
  margin-right: 10px;
}
.breadcrumb li:first-child {
  z-index: 9;
  position:relative;
}
.breadcrumb li a {
  border: 1px solid #006A9C;
  color: black;
  text-decoration: none;
  padding: 10px 10px 10px 10px;
  background: #fff;
  position: relative;
  display: block;
  float: left;
}
.breadcrumb li:first-child a:after {
  border-color:#fff;
  border-style: solid;
  border-width: 15px;
  bottom: -30px;
  box-shadow: 0 0 0 0 #c00, -1px 1px 0 1px #006A9C;
  content: "";
  height: 0;
  position: absolute;
  right: -29px;
  transform: rotate(-135deg);
  transform-origin: 0 0 0;
  width: 0;
  z-index: -1;
}

.breadcrumb li:first-child a {
  border-right: 0;
}
.breadcrumb li:last-child a {
  border-left: 0;
}
.breadcrumb li:last-child a:after{
  display:none;
}
.breadcrumb li:last-child a:before{
  border-color:#fff;
  border-style: solid;
  border-width: 15px;
  bottom: -30px;
  box-shadow: 0 0 0 0 #006A9C, -1px 1px 0 1px #006A9C;
  content: "";
  height: 0;
  position: absolute;
  left: -1px;
  transform: rotate(-135deg);
  transform-origin: 0 0 0;
  width: 0;  
}
.breadcrumb li:last-child a {
  padding-left: 28px;
}
.breadcrumb li a:hover {
  background: #006A9C;
  color: #fff;
}
.breadcrumb li a:first-child:hover::after {
  border-color:#006A9C;
}
&#13;
<ul class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Vehicles</a></li>
</ul>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

*{
  margin: 0;
  padding: 0;
}
.container{
  margin: 20px;
  display: flex;
  flex-direction: row;
  border: 1px solid skyblue;
  width: 200px;
  overflow: hidden;
}


.left,.right{
  display: inline-block;
  //border: 1px solid black;
  line-height: 50px;
  width: 100px;
  height: 100%;
  position: relative;

  
}

.right{
    text-align: center;
}
p:hover{
  background-color: skyblue;
  color: white;
}
.left::after{
  content:'';
  position: absolute;
  left: 70px;
  top: 3px;
  display: inline-block;
  width: 45px;
  height: 45px;
  z-index: 2;
  background:white;
  transform:rotate(-45deg);
  border-right: 1px solid skyblue;
  border-bottom: 1px solid skyblue;
  
}
.left:hover::after{
  background-color: skyblue;
}
<div class="container">
  <p class="left">LEFT</p>
  <p class="right">RIGHT</p>
</div>

这是我的最佳状态。

我希望它对你有用。