uni-app实现图片宽度100%、高度自适应的效果,常规的css方法不行,默认给height:auto;就看不到图片了,要想实现自适应高度效果,首先给图片设置 mode="widthFix"
1 | < view class = "img-info" > |
2 | < image mode = "widthFix" src = "../../static/img/p10.jpg" /> |
3 | < image mode = "widthFix" src = "../../static/img/p10.jpg" /> |
4 | < image mode = "widthFix" src = "../../static/img/p10.jpg" /> |
5 | < image mode = "widthFix" src = "../../static/img/p10.jpg" /> |
6 | </ view > |
样式中设置高度自适应 height:auto; 就可以了
01 | .img-info { |
02 | margin-top : 20 rpx; |
03 | display :flex; |
04 | flex-wrap: wrap; |
05 | justify- content : space-around; |
06 | image { |
07 | width : 320 rpx; |
08 | height : auto ; |
09 | margin-bottom : 20 rpx; |
10 | } |
11 | } |
以上是一行两列的图片布局效果,宽度固定,高度自适应