代码之家  ›  专栏  ›  技术社区  ›  Isaías Orozco Toledo

如何在css(部分填充的垂直血管效果)中的椭圆形内制作条带?

css
  •  1
  • Isaías Orozco Toledo  · 技术社区  · 6 年前

    我有一个椭圆形的,里面我想包括一个条带,使液体体积的水平。

    我做了这个:

        <style scoped>
    .strip:before {
      position: absolute;
      background: #343434;
      border-bottom: 2px solid black;
      content: "";
      position: absolute;
      z-index: -1;
      top: 0;
      right: 0;
      bottom: 15%;
      left: 0;
    }
    
    .oval div {
      position: absolute;
      background: #343434;
      background-repeat: repeat;
      border-width: thin 10px;
      transition: all;
      -moz-border-radius: 0 50% / 0 100%;
      -webkit-border-radius: 0 50% / 0 100%;
      border-radius: 150px;
      height: 100px;
      width: 80%;
    }
    </style>
    

    其结果是: enter image description here

    我想做的是,绿色部分是一个条形图,它可以根据液位改变其值。

    底部值,可能是一个不断变化的值。

    --编辑 我就是这样的

    <div class="oval" >
                <div class="strip" v-bind:style="{ background: props.item.color}"></div>
              </div>
    
    2 回复  |  直到 6 年前
        1
  •  3
  •   Alex Shesterov    6 年前

    如果您想要“部分填充”栏的效果,那么您可以使用单个 div 使用 linear-gradient 背景:

    .oval {
      --fill-level: 60%;
    
      background: linear-gradient(0deg, green var(--fill-level), black var(--fill-level));
      border-width: thin 10px;
      border-radius: 150px;
      height: 100px;
      width: 80%;
    }
    <div class="oval"></div>

    如果你改变了 0deg 90deg ,您将获得经典的水平“进度条”:

    .oval {
      --fill-level: 60%;
    
      background: linear-gradient(90deg, green var(--fill-level), black var(--fill-level));
      border-width: thin 10px;
      border-radius: 150px;
      height: 100px;
      width: 80%;
    }
    <div class=“椭圆形”></div>
        2
  •  1
  •   Wild Beard    6 年前

    你就快到了。可以使用单个元素执行此操作: .oval 。使用渲染的椭圆形,可以将 :before 伪选择器并添加行并控制行的 bottom 价值

    .oval {
      position: absolute;
      background: #343434;
      background-repeat: repeat;
      border-width: thin 10px;
      transition: all;
      -moz-border-radius: 0 50% / 0 100%;
      -webkit-border-radius: 0 50% / 0 100%;
      border-radius: 150px;
      height: 100px;
      width: 80%;
      overflow: hidden;
      background-color: green;
    }
    .oval:before {
      position: absolute;
      bottom: 25%;
      width: 100%;
      height: 3px;
      background: black;
      content: '';
    }
    <div class="oval"></div>

    或者可以使用单独的元素来完成,就像您在示例中尝试的那样。而不是尝试使用 :之前 .strip 元件制造商 你椭圆形的孩子。如果这样做,您将不需要 :之前 您的

    .strip {
      position: absolute;
      background: #343434;
      border-bottom: 2px solid black;
      z-index: 1;
      bottom: 25%;
      width: 100%;
      height: 3px;
    }
    
    .oval {
      position: absolute;
      background: #343434;
      background-repeat: repeat;
      border-width: thin 10px;
      transition: all;
      -moz-border-radius: 0 50% / 0 100%;
      -webkit-border-radius: 0 50% / 0 100%;
      border-radius: 150px;
      height: 100px;
      width: 80%;
      background-color: green;
      overflow: hidden;
    }
    <div class="oval">
      <div class="strip"></div>
    </div>