如何修复&:after元素之间的差距?

时间:2016-04-03 23:32:29

标签: css

如果你仔细观察下面的截图,你可以看到箭头左边有一点间隙。

我认为当元素没有像素对齐时会发生这种情况。我该如何解决这个问题?

jsbin



.stepList {
  zoom: 1;
  list-style: none;
  padding: 0;
  margin: 0 -15px 10px -15px;
  border-color: #E7EAEC;
  border-width: 1px;
  border-top-style: solid;
  border-bottom-style: solid;
}
.stepList:before,
.stepList:after {
  content: "";
  display: table;
}
.stepList:after {
  clear: both;
}
.stepList > li {
  float: left;
  text-align: center;
  background-color: white;
  position: relative;
}
.stepList > li.currentStep {
  background-color: #233646;
}
.stepList > li.currentStep:not(:last-child):after {
  border-left-color: #233646;
}
.stepList > li:hover {
  background-color: #B70103;
}
.stepList > li:hover .stepTitle {
  color: white;
}
.stepList > li:hover:not(:last-child):after {
  border-left-color: #B70103;
}
.stepList > li:not(:last-child):before,
.stepList > li:not(:last-child):after {
  left: 100%;
  top: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  z-index: 100;
}
.stepList > li:not(:last-child):after {
  border-color: rgba(35, 54, 70, 0);
  border-left-color: white;
  border-width: 14px;
  margin-top: -14px;
}
.stepList > li:not(:last-child):before {
  border-color: rgba(231, 234, 236, 0);
  border-left-color: #E7EAEC;
  border-width: 15px;
  margin-top: -15px;
}
.currentStep .stepTitle {
  color: white;
}
.stepNumber {
  display: inline-block;
  font-size: .9em;
  border-radius: 1em;
  text-align: center;
  line-height: 16px;
  padding: 0 .3333em;
  background-color: white;
  border: 2px solid #ccc;
  margin-right: 4px;
  color: black;
  font-weight: bold;
}
.stepWrap {
  padding: 4px 0;
  display: block;
}
a.stepWrap {
  text-decoration: none;
}

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<ul class="stepList">
    <li class="currentStep" style="width:25%;">
        <span class="stepWrap"><span class="stepNumber">1</span><span class="stepTitle">Customer Information</span></span>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">2</span><span class="stepTitle">Passenger Information</span></a>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">3</span><span class="stepTitle">Trip Itinerary</span></a>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">4</span><span class="stepTitle">Miscellaneous</span></a>
    </li>
</ul>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我只调整了:之前的边框左边为0px; 希望这是正确的答案。

&#13;
&#13;
.stepList {
  zoom: 1;
  list-style: none;
  padding: 0;
  margin: 0 -15px 10px -15px;
  border-color: #E7EAEC;
  border-width: 1px;
  border-top-style: solid;
  border-bottom-style: solid;
}
.stepList:before,
.stepList:after {
  content: "";
  display: table;
}
.stepList:after {
  clear: both;
}
.stepList > li {
  float: left;
  text-align: center;
  background-color: white;
  position: relative;
}
.stepList > li.currentStep {
  background-color: #233646;
}
.stepList > li.currentStep:not(:last-child):after {
  border-left-color: #233646;
}
.stepList > li:hover {
  background-color: #B70103;
}
.stepList > li:hover .stepTitle {
  color: white;
}
.stepList > li:hover:not(:last-child):after {
  border-left-color: #B70103;
}
.stepList > li:not(:last-child):before,
.stepList > li:not(:last-child):after {
  left: 100%;
  top: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  z-index: 100;
}
.stepList > li:not(:last-child):after {
  border-color: rgba(35, 54, 70, 0);
  border-left-color: white;
  border-width: 14px;
  margin-top: -14px;
}
.stepList > li:not(:last-child):before {
  border-color: rgba(231, 234, 236, 0);
  border-left-color: #E7EAEC;
  border-width: 15px;
  margin-top: -15px;
  border-left: 0px;
}
.currentStep .stepTitle {
  color: white;
}
.stepNumber {
  display: inline-block;
  font-size: .9em;
  border-radius: 1em;
  text-align: center;
  line-height: 16px;
  padding: 0 .3333em;
  background-color: white;
  border: 2px solid #ccc;
  margin-right: 4px;
  color: black;
  font-weight: bold;
}
.stepWrap {
  padding: 4px 0;
  display: block;
}
a.stepWrap {
  text-decoration: none;
}
&#13;
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<ul class="stepList">
    <li class="currentStep" style="width:25%;">
        <span class="stepWrap"><span class="stepNumber">1</span><span class="stepTitle">Customer Information</span></span>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">2</span><span class="stepTitle">Passenger Information</span></a>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">3</span><span class="stepTitle">Trip Itinerary</span></a>
    </li>
    <li style="width:25%;">
        <a href="" class="stepWrap"><span class="stepNumber">4</span><span class="stepTitle">Miscellaneous</span></a>
    </li>
</ul>
</body>
</html>
&#13;
&#13;
&#13;