CSS带尖底的矩形

huangapple go评论57阅读模式
英文:

CSS Rectangle with pointy bottom

问题

如何创建一个类似这样的步进器?我尝试使用clip-path重新创建它们,但只成功制作了水平的,而不是垂直的。我尝试了很多方法,但在撰写此代码时,这段代码是我最新的尝试。我需要它在li元素之前,所以我尝试使用::before,但箭头指向右侧,看起来更像播放按钮而不是步进器。

片段

.wrapper {
  height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.steps {
  position: relative;
  height: 80%;
  width: 75%;
  .step {
    height: 80px;
    display: flex;
    align-items: center;
    &::before {
      content: "";
      background: red;
      height: 110%;
      width: 15px;
      margin: 0 2rem;
      clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 100%, 25% 50%, 0% 50%);
    }
  }
}
<div class="steps">
  <div class="step">
    <p class="step-text">这是一步</p>
  </div>
  <div class="step">
    <p class="step-text">这是一步</p>
  </div>
  <div class="step">
    <p class="step-text">这是一步</p>
  </div>
</div>

如果您需要进一步的帮助,请随时提问。

英文:

How would you create a stepper like this? I tried recreating those with clip-path but only managed to make them horizontal not vertical. I've tried many thing but at the time of writing this, this code is the latest try I've made I need it to be before an li so I tried with the ::before but the arrow pointed to the right and looked more like a play button more than anything.

CSS带尖底的矩形

Snippet

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.wrapper {
  height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.steps {
  position: relative;
  height: 80%;
  width: 75%;
  .step {
    height: 80px;
    display: flex;
    align-items: center;
    &amp;::before {
      content: &quot;&quot;;
      background: red;
      height: 110%;
      width: 15px;
      margin: 0 2rem;
      clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 100%, 25% 50%, 0% 50%);
    }
  }
}

<!-- language: lang-html -->

&lt;div class=&quot;steps&quot;&gt;
  &lt;div class=&quot;step&quot;&gt;
    &lt;p class=&quot;step-text&quot;&gt;This is a step&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class=&quot;step&quot;&gt;
    &lt;p class=&quot;step-text&quot;&gt;This is a step&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class=&quot;step&quot;&gt;
    &lt;p class=&quot;step-text&quot;&gt;This is a step&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

使用 calc CSS 函数修复你的剪切路径:

.step{
  height: 3rem;
  display: flex;
  align-items: center;
  margin: 2px 0;
}

.step::before{

  --size: 0.4rem;
  
  content: "";
  background: #6ea639;
  height: calc(100% + var(--size));
  width: calc(var(--size) * 2);
  margin: 0 1rem 0 0;
  
  clip-path: polygon(
    0% 0%,                         /* 左上角 */
    50% var(--size),               /* 顶部中间 */
    100% 0%,                       /* 右上角 */
    100% calc(100% - var(--size)), /* 右下角 */
    50% 100%,                      /* 底部中间 */
    0% calc(100% - var(--size))    /* 左下角 */
  );
}

更多信息:使用剪切路径创建带形状的带子

英文:

Fix your clip-path by using calc CSS function:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.step{
  height: 3rem;
  display: flex;
  align-items: center;
  margin: 2px 0;
}

.step::before{

  --size: 0.4rem;
  
  content: &quot;&quot;;
  background: #6ea639;
  height: calc(100% + var(--size));
  width: calc(var(--size) * 2);
  margin: 0 1rem 0 0;
  
  clip-path: polygon(
    0% 0%,                         /* Top left */
    50% var(--size),               /* Top center */
    100% 0%,                       /* Top right */
    100% calc(100% - var(--size)), /* Bottom right */
    50% 100%,                      /* Bottom center */
    0% calc(100% - var(--size))    /* Bottom left */
  );
}

<!-- language: lang-html -->

&lt;div class=&quot;steps&quot;&gt;
  &lt;div class=&quot;step&quot;&gt;This is a step&lt;/div&gt;
  &lt;div class=&quot;step&quot;&gt;This is a step&lt;/div&gt;
  &lt;div class=&quot;step&quot;&gt;This is a step&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

More info: Ribbon shape using clip path

huangapple
  • 本文由 发表于 2023年3月7日 17:53:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定