【发布时间】:2020-03-25 18:57:59
【问题描述】:
我想构建一个步进器组件(尽量避免使用包)。我使用纯 HTML 模板和 CSS 创建了它,我想根据 x 数字调整 ::before 元素的大小。
类似width: ${100% / 4}。我使用方法尝试了这种方法并得到了渲染错误。是否有可能做到这一点?或者还有其他方法可以做到这一点?
请看我的脚本:
<template>
<div class="c-stepper">
<div class="step-item" :style="drawLinePrecision(4)" v-for="item in 4" :key="item">
<div class="step-marker">
<i class="icon icon-duotones-check"></i>
</div>
<div class="step-info">
<p class="step-title">Step 1</p>
</div>
</div>
</div>
</template>
<script>
export default {
methods: {
drawLinePrecision(length) {
return `.step-item:not(:last-child)::before {
content: "";
height: 3px;
width: ${(100% / length)};
position: absolute;
top: 25%;
background-color: $primary;
}`
}
}
}
</script>
<style lang="scss" scoped>
@import "../../sass/variables";
.c-stepper {
display: flex;
justify-content: space-around;
align-items: center;
margin: 5rem 0rem;
position: relative;
.step-item {
&:not(:last-child)::before {
content: "";
height: 3px;
width: calc(100% / 4);
position: absolute;
top: 25%;
background-color: $primary;
}
.step-marker {
position: relative;
width: 50px;
height: 50px;
background-color: white;
border: 3px solid $primary;
border-radius: 50%;
.icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
}
}
</style>
【问题讨论】:
-
当我增加
step-item的数量时,它的大小并不精确
标签: vue.js