css С不能让“::before”伪元素在“::after”之后

lymnna71  于 2023-05-02  发布在  其他
关注(0)|答案(1)|浏览(108)

下面是布局上显示的内容:

我是这么做的

有没有布局和我做的网站之间的差异,但当涉及到自适应..

代码如下:

.expertise__content{
  display: flex;
  justify-content: space-between;
  margin-bottom: 130px;
}

.expertise__content-items{
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.expertise__content-item{
  font-size: 11px;
  line-height: 1.8;
  color: #1D1D1D;
  font-weight: 600;
  letter-spacing: 1px;
  width: 370px;
  max-width: 370px;
  border-top: 2px solid #1D1D1D;
  position: relative;
}

.expertise__content-item::before{
  content: '';
  position: absolute;
  bottom: 100%;
  right: 0;
  border-bottom: 2px solid #F0F0F0;
  width: 10%;
}

.expertise__content-item::after{
  content: "90%";
  padding-left: 262px;
}

#expertise__content-item-two::before{
  width: 20%;
}

#expertise__content-item-three::before{
  width: 15%;
}

#expertise__content-item-two::after{
  content: "80%";
  padding-left: 244px;
}

#expertise__content-item-three::after{
  content: "85%";
  padding-left: 218px;
}
<div class="expertise__content">
  <div class="expertise__content-items">
    <div class="expertise__content-item" id="expertise__content-item-one">BRANDING</div>
    <div class="expertise__content-item" id="expertise__content-item-two">DESIGN</div>
    <div class="expertise__content-item" id="expertise__content-item-three">DEVELOPMENT</div>
  </div>

我如何使百分比精确地在expertise__content-item上面的线之后?
尝试使用padding-left: ...%;解决此问题,但没有帮助

ih99xse1

ih99xse11#

我会考虑一个不同的想法,用更少的代码。我依靠一个CSS变量来调整代码中的每一个,所以你所要做的就是更新这个变量。
我假设你有足够的空间为文字和百分比,否则它不会呈现良好。

.progress {
  font-family: monospace;
  text-transform: uppercase;
  font-size: 17px;
  font-weight: bold;
  padding-top: 5px;
  margin: 20px 0;
  /* the gradient will create the progress bar*/
  background:
    linear-gradient(90deg, #000 calc(var(--p)*1%), #ccc 0)
    top/100% 2px no-repeat;
  /* flexbox to place the content */  
  display: flex;
  justify-content: space-between;
}

.progress:after {
  content: attr(style) "%"; /* show the content of the variable */
  /* trim the first 4 charater (--p:)*/
  text-indent: -4ch;
  overflow: hidden;
  /**/
  /* the margin will push the value from the right to place it correctly */
  margin-right: calc((100 - var(--p))*1%);
  /* transform will make sure we have the number centred */
  transform: translate(50%);
}
<div class="progress" style="--p:80">Branding</div>
<div class="progress" style="--p:50">Design</div>
<div class="progress" style="--p:65">Development</div>

相关问题