css Vue尺子样式

原生css生成尺子样式
在这里插入图片描述
在这里插入图片描述

<template>
  <div class="page">
    <div class="Light">
    </div>
    <div class="rile">
      <ul id="list">
        <!--尺子需要几个单位就加几个-->
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'temDiv',
  data() {
    return {
      
    };
  },
  mounted() {
  },

  methods: {
    
  },
};
</script>

<style lang="less" scoped>
.page {
  // 尺子的总宽度
  width: 800px;
  margin: 300px;
  .Light {
    height: 60px;
    width: 100%;
    display: flex;
    justify-content: center;
    background-color: #fff;
  }
  .rile {
    width: 100%;
    position: relative;
  }
  // 单位
  ul{
    position: absolute;
    left: 0;
    right: 0;
    list-style: none;
    //counter-reset: num -2;  // 由于间隔数字是2,减2则从0开始
    counter-reset: num -1;  // 由于间隔数字是1,减1则从0开始
    width: 100%;
    padding-inline-start: 0px;
    display: flex;
    justify-content: space-between;
  }
  #list>li {
    width: 1px;
    height: 6px;
    background-color: black;
    position: relative;
  }
  #list>li:before{
    //counter-increment: num 2;  //间隔数字为2
    counter-increment: num 1;  //间隔数字为1
    content: counter(num);
    position: absolute;
    top: 5px;
    left: -4px;
  }
}
</style>
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue项目中,样式污染是指当页面增加时,重复调用同一种组件会造成样式冲突的问题。这个问题主要有两个原因导致。首先,使用了同一种组件,但在CSS中对该组件设置了不同的样式。其次,子元素的根元素会继承父元素的ScopeId。为了解决这个问题,有几种方法可以尝试。 一种解决方案是在每个Vue页面的style标签中添加scoped属性。scoped的原理是给CSS和HTML添加一个唯一标识,并根据权重来实现目的。scoped的作用是使得Vue组件中的样式不会影响其他Vue组件,但不是让Vue组件样式不受外界影响。然而,scoped需要谨慎使用。在需要修改公共组件(第三方库或项目中定制的组件)的样式时,scoped会导致一些麻烦。针对这种情况,可以在style标签中使用两个样式,将修改公共组件的样式放在一个style标签中,而将其他样式放在另一个带有scoped属性的style标签中。 另一种解决方案是使用不同的class来区分不同的表格分页控件。比如,对于sos表格,可以在template中设置一个特殊的class,然后在CSS样式中使用该class名和属性名称来设置分页的背景颜色。对于emergencytask表格,可以在template中设置一个不同于其他表格分页的class,然后在CSS样式中使用该class名和属性名称来设置分页的背景颜色。这样,可以避免样式的重叠和干扰。 综上所述,为了解决Vue项目中的样式污染问题,可以使用scoped属性来限制组件样式的影响范围,同时要注意scoped的使用场景。另外,可以使用不同的class来区分不同的表格分页控件,以避免样式的冲突。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [浅谈VUE中的样式污染问题](https://blog.csdn.net/qq_33204193/article/details/87886269)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值