vue(css)实现三个字和四个字等宽、或者3个字和2个字等宽

效果图:
在这里插入图片描述

在做前台界面的时候,比如一些文字的列表或者一些表单的标题,经常是2个字,3个字,4个字的类型。
一般对齐就是在中间打空格或者用 来空开,但是效果并不好,兼容性有问题,造成不美观。
letter-spacing 属性增加或减少字符间的空白(字符间距)。
该属性定义了在文本字符框之间插入多少空间。由于字符字形通常比其字符框要窄,指定长度值时,会调整字母之间通常的间隔。

上面效果图的代码:

<div slot="label" style="font-size: 14px;letter-spacing:0.33em;">收件人:</div>

提示:具体的letter-spacing数值,请根据实际显示效果进行调整。
“em” 表示相对于font-size大小的长度。letter-spacing也可以使用"px"作为单位

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我可以为您提供一个VUE的抽奖代码示例。以下是代码: ``` <template> <div class="container"> <h1>抽奖</h1> <div class="lottery-box"> <div class="prize" v-for="prize in prizes" :key="prize.index" :class="{active: prize.isActive}"> <img :src="prize.image" alt=""> <div class="prize-name">{{ prize.name }}</div> </div> </div> <button class="btn" @click="startLottery" :disabled="!canStart">开始抽奖</button> </div> </template> <script> export default { data() { return { prizes: [ { index: 1, name: '一等奖', image: '/img/prize1.jpg', isActive: false }, { index: 2, name: '二等奖', image: '/img/prize2.jpg', isActive: false }, { index: 3, name: '三等奖', image: '/img/prize3.jpg', isActive: false }, { index: 4, name: '幸运奖', image: '/img/prize4.jpg', isActive: false }, ], activeIndex: -1, isStarted: false, canStart: true, }; }, methods: { startLottery() { if (this.isStarted) { return; } this.isStarted = true; this.canStart = false; this.activeIndex = -1; let index = 0; const timer = setInterval(() => { index++; if (index > this.prizes.length - 1) { index = 0; } this.activeIndex = index; }, 50); setTimeout(() => { clearInterval(timer); this.isStarted = false; this.prizes.forEach((prize) => { prize.isActive = false; }); const winnerIndex = Math.floor(Math.random() * this.prizes.length); this.prizes[winnerIndex].isActive = true; this.activeIndex = winnerIndex; this.canStart = true; }, 3000); }, }, }; </script> <style> .container { text-align: center; } .lottery-box { margin-top: 50px; display: flex; justify-content: center; } .lottery-box .prize { width: 200px; height: 200px; margin: 20px; position: relative; cursor: pointer; transform: rotate(0deg); transition: all 3s ease-out; } .lottery-box .prize img { width: 100%; height: 100%; object-fit: cover; } .lottery-box .prize-name { position: absolute; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; font-size: 24px; font-weight: bold; color: #fff; background: rgba(0, 0, 0, 0.5); transition: all 0.3s ease-out; transform: translateY(200px); } .lottery-box .prize.active .prize-name { transform: translateY(0); } .btn { margin-top: 50px; padding: 20px; background: #ffcc00; font-size: 24px; font-weight: bold; color: #fff; border: 0; border-radius: 5px; cursor: pointer; } .btn:disabled { background: #ccc; cursor: default; } </style> ``` 这个抽奖代码使用VUE编写。在这个示例代码中,您可以看到一个抽奖盒子,其中包含四个奖项图片和名称,还有一个开始抽奖的按钮。当用户点击“开始抽奖”按钮时,抽奖将开始并在3秒内随机选择一个获奖者。在抽奖过程中,盒子中的奖项将随机旋转,直到最终结果。希望这个VUE抽奖代码示例能对您有所启发!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值