flex布局,image宽高不能设定?求助
发布于 5 年前 作者 xia86 12733 次浏览 来自 问答

wxml:

<view class='one'>
          <image src='/1.png' class='image' mode='aspectFill'></image>
          <text >中央公园垃圾成堆,中央公园垃圾成堆,中央公园垃圾成堆,中央公园...</text>
</view>

css:

.one {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  font-size: 30rpx

}


.image {

width: 120rpx;

height: 120rpx;

margin-right: 20rpx;

}

结果,图片宽不是120rpx,mode = ‘aspectFill’ 不是会自动截图的吗?

想不明白,以前用flex后都会根据设置自动布局。:(

弄了好久,感觉自己学的都是假css,于是我给text加了个固定宽度…

<view class='one'>
          <image src='/1.png' class='image' mode='aspectFill'></image>
          <text class='fuck'>中央公园垃圾成堆,中央公园垃圾成堆,中央公园垃圾成堆,中央公园...</text>

</view>




.fuck{

  width: calc(100% - 120rpx)

}


结果好了!!??

固定宽度这个倒是好理解,就是不明白在flex布局下为什么会失效。郁闷,求解。感谢。:)

2 回复

给图片的样式加flex:none

flex-shrink: 0

回到顶部