在 div 中居中显示垂直虚线

Displaying a vertical dashed line centrally in a div

使用 StyledComponents 进行 React,下面的每个 <div> 代表一个不同的 Styled Component。

正在努力实现这样的目标:

但理想情况下,我想在 progress-indicator 中添加“虚线”样式,使其垂直位于指示器下方并跨越 wrapping-container 的整个高度。我试过使用 ::before & ::after 但没有成功。

.wrapping-container {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.progress-indicator {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  border-radius: 50%;
  border: 1px solid rgb(255, 255, 255);
  background: rgb(39, 40, 42);
  color: rgb(255, 255, 255);
  font-size: 13px;
  text-align: center;
}


.input {  
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
}
<div class="wrapping-container">
  <div class="progress-indicator">2</div>
  <div class="input">Input</div>
</div>  


<div class="wrapping-container">
  <div class="progress-indicator">3</div>
  <div class="input">Input</div>
</div>  

实现此目的的简单(如果粗略)方法:

.dasher {
    border: 1px dashed #ced4da;
    max-width: 0px;
    min-height: 10px;
    margin-left: 10px;
    margin-top: -20px;
}

演示

.wrapping-container {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.progress-indicator {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  border-radius: 50%;
  border: 1px solid rgb(255, 255, 255);
  background: rgb(39, 40, 42);
  color: rgb(255, 255, 255);
  font-size: 13px;
  text-align: center;
}


.input {  
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
}

.dasher {
    border: 1px dashed #ced4da;
    max-width: 0px;
    min-height: 10px;
    margin-left: 10px;
    margin-top: -20px;
}
<div class="wrapping-container">
  <div class="progress-indicator">2</div>
  <div class="input">Input</div>
</div>

<div class="dasher"></div>

<div class="wrapping-container">
  <div class="progress-indicator">3</div>
  <div class="input">Input</div>
</div>

应该给你这个:

我添加了一个容器和一个虚线块,它们将直接穿过所有高度 wrapping-container:

.container{
  position:relative;
}
.border-dash{
  position: absolute;
  top: 15px;
  left: 11px;
  border-left: 1px dashed black;
  height:calc(100% - 25px);
  width: 1px;
  display: block;
  z-index: -1;
}

演示

.wrapping-container {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.progress-indicator {
  height: 22px;
  width: 22px;
  margin-right: 16px;
  border-radius: 50%;
  border: 1px solid rgb(255, 255, 255);
  background: rgb(39, 40, 42);
  color: rgb(255, 255, 255);
  font-size: 13px;
  text-align: center;
}


.input {  
  border: 1px solid #ced4da;
  border-radius: 2px;
  overflow-y: hidden;
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
}
.container{
  position:relative;
}
.border-dash{
  position: absolute;
  top: 15px;
  left: 11px;
  border-left: 1px dashed black;
  height:calc(100% - 25px);
  width: 1px;
  display: block;
  z-index: -1;
}
<div class="container">

  <span class="border-dash"></span>
  
  <div class="wrapping-container">
    <div class="progress-indicator">2</div>
    <div class="input">Input</div>
  </div>  

  <div class="wrapping-container">
    <div class="progress-indicator">3</div>
    <div class="input">Input</div>
  </div>

  <div class="wrapping-container">
    <div class="progress-indicator">4</div>
    <div class="input">Input</div>
  </div>
</div>

我的方法如下:

.wrapping-container {
    position: relative;
    display: flex;
}
.progress-indicator {
    position: relative;
    display: inline-block;
    margin-bottom: 40px;
    color: #fff;
}
.progress-indicator::after {
    content: "";
    width: 30px;
    height: 30px;
    background: #000;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    z-index: -1;
}
.progress-indicator::before {
    content: "";
    height: 40px;
    border: 1px dashed #000;
    position: absolute;
    left: 50%;
    top: -50px;
    transform: translateX(-50%);
    z-index: -1;
}
.input {
    margin-left: 30px;
}
<div class="wrapping-container">
    <div class="progress-indicator">2</div>
    <div class="input">Input</div>
</div>  
<div class="wrapping-container">
    <div class="progress-indicator">3</div>
    <div class="input">Input</div>
</div>