需要面包屑周围的边界

时间:2018-11-14 11:05:53

标签: html css border breadcrumbs pseudo-class

我创建了一个包含3个项目的面包屑。 现在,在每个项目上悬停时,我需要显示一个如图所示的边框,但是当前它不符合预期。

如何在面包屑上添加边框? 另外,请让我知道是否可以简化现有CSS以获得相同的外观。

静态HTML必须相同。

这是悬停时的预期图像。

enter image description here

代码如下:

* {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 12px;
}

h1 {
  font-weight: 100;
  font-size: 32px;
  padding: 40px;
  color: #fff;
}

#breadcrumb {
  list-style: none;
  display: flex;
}
#breadcrumb .icon {
  font-size: 14px;
}
#breadcrumb a {
  width: 13.33%;
  justify-content: flex-start;
  text-decoration: none;
}
#breadcrumb a span {
  color: #a9a9a9;
  display: block;
  background: #D3D3D3;
  position: relative;
  height: 40px;
  line-height: 40px;
  padding: 15px 40px 15px 25px;
  text-align: center;
  margin-right: 23px;
}
#breadcrumb a:first-child span {
  padding-left: 15px;
  border-radius: 4px 0 0 4px;
}
#breadcrumb a:first-child span:before {
  border: none;
}
#breadcrumb a:last-child {
  width: 20%;
  border: none;
  justify-content: flex-end;
} 
#breadcrumb a:last-child span {
  padding-right: 15px;
  border-radius: 0 4px 4px 0;
}

#breadcrumb a:last-child span:after {
  border: none;
} 

#breadcrumb a span:before, #breadcrumb a span:after {
  content: "";
  position: absolute;
  top: 0;
  border: 0 solid #D3D3D3;
  border-width: 35px 15px;
  width: 0;
  height: 0;
}
#breadcrumb a span:before {
  left: -20px;
  border-left-color: transparent;
}
#breadcrumb a span:after {
  left: 100%;
  border-color: transparent;
  border-left-color: #D3D3D3;
}

#breadcrumb a:hover {
  margin: 0 3px;
}
<div id="breadcrumb">
   <a href="#"><span>1</span></a>
   <a href="#"><span>2</span></a>
   <a href="#"><span>3</span></a>
</div>

0 个答案:

没有答案
相关问题