VenusYan 2023-04-13 17:34 采纳率: 100%
浏览 21
已结题

小程序wxml样式书写 带背景圆圈文字

小程序wxml样式书写 带背景圆圈文字




<view class="cld-bottom">
   <text wx:for='{{slotArr}}' wx:key='index'>{{item.text}}
   </text>
</view>

/* pages/checkin/checkin.wxss */

.cld-bottom{
  height:calc(100% - 130rpx);
  padding:10rpx;
  padding-top:0;
  font-size:29rpx;
}
.cld-bottom text{
  position: relative;
  display: inline-block;
  text-align: center;
  width:13%;
  margin-left:1.5%;
  margin-top:44rpx;
}
.cld-bottom text:nth-child(7n-6){
  margin-left:0;
}

现效果图如下

img

希望做改动:在数字后设置底色圆框(分为上半下半)
大致效果如下22,但圆圈需分为上下,可根据js的不同情况渲染不同颜色

img

求样式该怎么书写

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2023-04-13 17:39
    关注

    圆圈border-radius:50%,用wx.getSystemInfoSync()获取屏幕宽度,计算下宽度和高度。text容器改为view,示例如下
    js

     
    Page({
       data:{
         width:'',
         height:'',
        slotArr:[]
       },
       onLoad(){
         let screenWidth=wx.getSystemInfoSync().screenWidth;
         let padding=Math.floor(20*screenWidth/750);//容器padding转px
         let areaWidth=screenWidth-padding;//得到显示区域宽度
         let wh=Math.floor(areaWidth*.13);//每项日期宽度
         console.log(areaWidth,padding,screenWidth,wh)
         this.setData({width:wh+'px',height:wh+'px'})
         let slotArr=[];
         for(let i=1;i<=30;i++)slotArr.push({text:i});
         
         slotArr[3].cls='circle';//圆形样式,使用默认背景色
    
         slotArr[7].cls='circle';//圆形样式
         slotArr[7].bgColor='#f00';//设置红色背景
    
         this.setData({slotArr})
       }
    })
    
    

    wxml

    <view class="cld-bottom">
       <view wx:for='{{slotArr}}' class="{{item.cls}}" wx:key='index' style="width:{{width}};height:{{height}};line-height:{{height}};background-color:{{item.bgColor}}">
       {{item.text}}
       </view>
    </view>
    
    
    
    

    wxss

    .cld-bottom{
      height:calc(100% - 130rpx);
      padding:10rpx;
      padding-top:0;
      font-size:29rpx;
    }
    .cld-bottom view{
      position: relative;
      display: inline-block;
      text-align: center;
      width:13%;
      margin-left:1.5%;
      margin-top:44rpx;
    }
    .cld-bottom view:nth-child(7n-6){
      margin-left:0;
    }
    .cld-bottom view.circle{border-radius: 50%;color:#fff;background-color: #53acfc;}
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 已采纳回答 4月14日
  • 创建了问题 4月13日

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?