【发布时间】:2017-03-17 09:55:09
【问题描述】:
我有一些漂亮的 CSS:
$itemHeight: 40px;
$arrowModifier: 8;
$pageBackgroundColor: $color-gray-50;
.processBar {
display: flex;
flex-wrap: wrap;
&_item {
display: inline-block;
background: $color-gray-200;
height: $itemHeight;
position: relative;
flex-grow: 1;
text-align: center;
line-height: $itemHeight;
text-decoration: none;
color: $color-text;
padding-left: 10px;
padding-right: 10px;
&:hover {
text-decoration: none;
color: $color-text;
}
&-default {
&:hover {
background: $color-light-gray;
}
}
&-selected {
background: $color-white;
}
&:before,
&:after {
display: inline-block;
content: "";
border-style: solid;
position: absolute;
}
&:first-child {
&:before {
left:0;
border: none;
}
}
&:not(:first-child) {
&:before {
left:0;
border-color: transparent transparent transparent $pageBackgroundColor;
border-width: $itemHeight/2 0 $itemHeight/2 $itemHeight/$arrowModifier;
}
}
&:last-child {
&:after {
right: 0;
border: none;
}
}
&:not(:last-child) {
&:after {
right:0;
border-color: $pageBackgroundColor transparent;
border-width: $itemHeight/2 0 $itemHeight/2 $itemHeight/$arrowModifier;
}
}
}
}
这是使用它的 HTML:
<div class="processBar">
<a href="javascript:" class="processBar_item">Label</a>
<a href="javascript:" class="processBar_item">Label</a>
<a href="javascript:" class="processBar_item">Label</a>
<a href="javascript:" class="processBar_item">Label</a>
<a href="javascript:" class="processBar_item">Label</a>
<a href="javascript:" class="processBar_item">Label</a>
</div>
这是它的作用:
但在一定大小时,:after 元素可以向下跳,如下所示:
我不明白为什么会这样。我怎样才能阻止它发生?
【问题讨论】:
标签: css flexbox pseudo-element