关于微信小程序css样式中calc属性不生效问题的解决方案

关于微信小程序css样式中calc属性不生效问题的解决方案,第1张

问题:在微信小程序中使用height:calc(xx - xx)设置元素高度无效

排查原因:calc属性设置height或width时,要求父容器有明确的对应属性设置,当父容器没有设置时,calc计算无法完成。因为我想设置高度的元素没有父容器,所以calc失效。

解决办法:1.给该元素添加设置明确高度的父容器。2.直接通过page{height:100%}解决。

1、新建目录calc

2、pages加上

"pages/calc/calc",

3、 calc.wxml

<view class="container">

<input placeholder="被加数" bindinput="bindInput1" />

<input placeholder="加数" bindinput="bindInput2" />

<button type="primary" bindtap="bindAdd">计算</button>

<input placeholder="结果" value="{{result}}" disabled />

</view>

4、calc.wxss

/* pages/calc/calc.wxss */

.container{

justify-content: flex-start

padding: 30rpx 0

}

.container input{

background-color: #eee

border-radius:3px

text-align:left

width:720rpx

height:100rpx

line-height:100rpx

margin:20rpx

}

.container button{

width:80%

}

5、calc.json

{

"navigationBarBackgroundColor":"#00ff00",

"navigationBarTitleText":"加法计算器",

"navigationBarTextStyle":"white",

"usingComponents": {}

}

6、calc.js

// pages/calc/calc.js

Page({

/**


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8090948.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存