如何在伪元素之后居中?

How to center after pseudo-elements?

我有一个元素列表,我在元素(垂直线)之后添加了,我想将它居中,它应该是 响应式的。

这就是我想要的

这是我的解决方案

.profile_card-bottom {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  margin-bottom: 64px;
}

li::after {
  -webkit-transition: all 0.15s ease-in-out;
  transition: all 0.15s ease-in-out;
  content: '';
  display: block;
  float: left;
  background-color: #979797;
  width: 1px;
  opacity: 0.1;
  height: 77px;
  position: absolute;
  bottom: 13px;
  right: -57px;
}

li:nth-child(3n)::after {
  display: none;
}

li:nth-child(4n)::after {
  display: none;
}

.likes,
.following,
.followers,
.follow {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  position: relative;
}

.btn-follow {
  background: $button-color;
  border-radius: 100px;
  border: none;
  outline: none;
  height: 92px;
  width: 268px;
  font-size: 30px;
  color: #FFFFFF;
  font-weight: 600;
  letter-spacing: 4.2px;
  position: relative;
  right: 37px;
  top: 9px;
  text-transform: uppercase;
  cursor: pointer;
}

.assets-count {
  font-size: 48px;
  color: $li-span-color;
  letter-spacing: 0;
  font-weight: 400;
}

.assets-title {
  font-size: 20px;
  color: $h1-span-color;
  letter-spacing: 0;
  line-height: 11px;
  font-weight: $base-font-weight;
}


}
<ul class="profile_card-bottom">
  <li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
  <li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
  <li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
  <li class="follow"><button class="btn-follow">Follow</button></li>
</ul>

不幸的是,我的解决方案没有给我想要的结果,

我的解决方案哪里做错了?任何帮助将不胜感激,谢谢

我认为您可能误解了 :after 生成的内容在文档流中的最终位置。

The pseudo-elements generated by ::before and ::after are contained by the element's formatting box...

所以after元素实际上并不是放在<li>之后,而是放在<li>的子节点的末尾[=17] =]

.profile_card-bottom {
  display: flex;
  justify-content: space-between;
}

li {
  display: flex;
  flex: 1 1 auto;
}

li:not(:last-child):after {
  content: '';
  display: block;
  background-color: #979797;
  width: 1px;
  opacity: 1;
  height: 77px;
  margin: 0 auto;
  height: 100%;
}
<ul class="profile_card-bottom">
  <li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
  <li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
  <li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
  <li class="follow"><button class="btn-follow">Follow</button></li>

</ul>

我建议您使用 div 而不是 span,这样您就不需要对 span 使用 CSS 来使其阻塞(弹性)。此外,使用 li:nth-child(-n + 2)::after 而不是使用新规则分隔最后两个 li 的样式。

请参阅下面的代码段:

* {
 font-family: "calibri"; 
}
.profile_card-bottom {
  display: flex;
  justify-content: space-between;
}

li {
  display: flex;
  flex: 1 1 auto;
}


li:nth-child(-n + 2)::after {
 content: '';
  display: block;
  background-color: #979797;
  width: 1px;
  opacity: 0.1;
  height: 77px;
  margin: 0 auto;
  height: 100%;
}

li:nth-child(3n)::after {
  display: none;
}

li:nth-child(4n)::after {
  display: none;
}

li span {  
  display: block;
}

.btn-follow {
  background: #FFA640;
  border-radius: 100px;
  border: none;
  outline: none;
  height: 50px;
  width: 180px;
  font-size: 20px;
  color: #FFFFFF;
  font-weight: 600;
  letter-spacing: 4.2px;
  position: relative;
  right: 37px;
  top: 9px;
  text-transform: uppercase;
  cursor: pointer;
}

.assets-count {
  font-size: 38px;
  color: #FFA640;
  letter-spacing: 0;
  font-weight: 400;
}

.assets-title {
  font-size: 15px;
  color: #8298B9;
  letter-spacing: 0;
  line-height: 11px;
  font-weight: 200;
}
<ul class="profile_card-bottom">
  <li class="likes"><div><span class="assets-count">124</span><span class="assets-title">Likes</span></div></li>
  <li class="following"><div><span class="assets-count">727</span><span class="assets-title">Following</span></div></li>
  <li class="followers"><div><span class="assets-count">4437</span><span class="assets-title">Followers</span></div></li>
  <li class="follow"><button class="btn-follow">Follow</button></li>
</ul>

你也可以测试一下here

P.S。 - 我已经改变了颜色和字体看起来像提供的图像;

它将与响应一起工作,试试这个代码

.profile_card-bottom {
     display: flex;
     justify-content: space-between;
     padding: 0;
   }

   li {
     display: inline-flex;
     flex: 1 1 auto;
     -webkit-flex-flow: row wrap;
     flex-flow: row wrap;
     -webkit-align-items: center;
     align-items: center;
     position: relative;
        font-family: sans-serif;

   }

   li:not(:last-child):after {
     content: '';
     display: block;
     background-color: #ccc;
     width: 1px;
     opacity: 1;
     margin: 0 auto;
     height: 100%;
     position: absolute;
     right: 0;
   }

   li span {  
     display: flex;
     flex: 1 100%;  
     justify-content: center;
   }

   .btn-follow {
     background: #FFA640;
     border-radius: 50px;
     border: none;
     outline: none;
     font-size: 3vh;
     letter-spacing: 1px;
     color: #FFFFFF;
     font-weight: 600;   
     text-transform: uppercase;
      display: flex;
     flex: 1 80%;  
     justify-content: center;
     padding: 7px 15px;
     margin: 0 3px;
   }

   .assets-count {
     font-size: 4.5vh;
     color: #FFA640;
     letter-spacing: 0;
     font-weight: 400;
   }

   .assets-title {
     font-size: 2.5vh;
     color: #8298B9;
     letter-spacing: 0;
     font-weight: 200;
   }
<ul class="profile_card-bottom">
    <li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
    <li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
    <li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
    <li class="follow"><button class="btn-follow">Follow</button></li>
  </ul>