解决text-align: justify;在微信小程序中不兼容

本文介绍了一种在WXML中通过添加空标签实现文字对齐的方法,适用于需要精确控制UI布局的场景。通过调整CSS样式,可以确保不同长度的文字都能均匀对齐。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 百度了其他大佬的,在项目中试验了一下,核心是在文字后边加一个空标签

<view class="ka-left" >
      <view class="ka-name">{{monthlypay[m].month}}卡<text class="hid"></text></view>
      <view class="ka-jine"> ¥{{monthlypay[m].jine}} </view>
</view>
.ka-name{
        width: 100rpx;
        height: 100rpx;
        line-height: 100rpx;
        text-align: justify;
        text-align-last: justify;
        text-justify: inter-ideograph; /** 增加或减少词间的空格 **/
        .hid{
          display:inline-block; 
          width:100%;
        }
}

<template> <view class="container"> <view class="title"> <view class="headSpan">照明</view> <view class="lineSpan">行业智能供应链</view> </view> <view class="search-top search-normal"> <view class="search-box"> <input placeholder="请输入" type="text" v-model="searchText" /> </view> </view> <IndustryData></IndustryData> </view> </template> <script setup> import IndustryData from "@/components/IndustryData.vue" import { ref } from 'vue'; let searchText = ref('') </script> <style lang="scss"> @import "../../static/scss/publicContainer.scss"; $boxs-margin: 10px; //每个盒子之前的margin距离 .title { text-align: center; font-family: "PangMenZhengDao"; font-style: normal; display: flex; flex-direction: column; height: 50px; .headSpan { font-family: "PangMenZhengDao"; display: flex; width: 88px; height: 25px; flex-direction: column; justify-content: center; font-size: 22px; font-weight: 800; line-height: 22px; letter-spacing: 2.4px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .lineSpan { display: flex; width: 88px; height: 15px; flex-direction: column; justify-content: center; flex-shrink: 0; font-family: "PangMenZhengDao"; font-size: 10px; font-weight: 800; line-height: 12px; letter-spacing: 1px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } } .search-top { position: sticky; top: calc(var(--status-bar-height) + $marginHead + $boxs-margin); } .search-normal { width: 65vw; } .search-box { display: flex; padding: 6px 12px; height: 28px; align-items: center; flex: 1 0 0; align-self: stretch; border-radius: 30px; background-color: #E6E6E6; color: black; z-index: 999; margin: $boxs-margin auto; } </style> 帮我修改代码,做到sticky触发的时候searchbox宽度为width: 65vw;,但是正常时候是100
06-20
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佛佛ง

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值