关于 flex-direction: column 之后宽度自动变为100%的解决办法

3 篇文章 0 订阅

关于 flex-direction: column 之后宽度自动变为100%的解决办法

前提介绍:要实现这么个东西,想到了使用 flex

html:

<divclass="left cardp"slot="left">

<divclass="label":style="{color:'#cd329a','border-color':'#cd329a'}">净值理财</div>

<divclass="clearnum">1.1467</div>

<divclass="text">单位净值</div>

</div>

stylus:

.cardp
  display flex
  flex-directioncolumn
  justify-contentspace-between
.label
  display inline-block
  padding 0.266667rem/* 20/75 */
  height .56rem/* 42/75 */
  border .026667rem/* 2/75 */ solid#cd329a
  color #cd329a
  line-height .56rem
  text-align center
  border-radius .266667rem/* 20/75 */
  font-size 25px;/*px*/

 

然后发现使用了  flex-directioncolumn之后,那个  净值理财 变成了宽度 100%、如下图

解决

这就很讨厌了,我不想设置死了这个宽度,想让他自动适应,但是结果宽度变成了 100%

然后不断地试,发现

在 .label加一句话   

align-self: baseline

竟然成功了!  最后的  stylus:

.cardp
  display flex
  flex-directioncolumn
  justify-contentspace-between
.label
  display inline-block
  padding 0 .266667rem/* 20/75 */
  height .56rem/* 42/75 */
  border .026667rem/* 2/75 */ solid#cd329a
  color #cd329a
  line-height .56rem
  text-align center
  border-radius.266667rem/* 20/75 */
  font-size 25px;/*px*/
  align-self: baseline

 

    还是这张图

查了资料,发现 baseline 的解释为

然后继续试,发现只要给 align-self:设置一个值,就能实现这个目的,因为 默认值为 

align-self: stretch

修改这个默认值,就能防止 100%

 

 

 

 

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值