Vue3 & TypeScript ---- 伪元素动态样式

2023-09-25  本文已影响0人  牛会骑自行车
效果图
<script lang="ts" setup>
const beforeWidth = ref('50px');
</script>

<template>
  <div class="fake-view" :style="{'--width': beforeWidth}"></div>
</template>

<style lang="scss" scoped>
.fake-view {
  height: 40px;
  background: lightgrey;
  position: relative;
}
.fake-view::before {
  content: '';
  display: block;
  width: var(--width);
  height: 100%;
  background: red;

  position: absolute;
  top: 0;
  left: 0;
}
</style>
上一篇 下一篇

猜你喜欢

热点阅读