不去做怎么知道做不到,用心做好每一天做好每一件事。|

轻风细雨_林木木

园龄:6年3个月粉丝:4关注:1

学习日记--flex保持子div不变

目标:在perent-div中 child-div中的其中一个不改变宽度

这里要借助flex的item属性,也许很多人会觉得很难,其实很简单,我说说我是怎么记得。

首先知道有六个属性
然后知道 flex-grow 和 flex-basis 是在有剩余空间使用
flex-shrink 是没有剩余空间使用
这样就记住一半了,
然后余下的基本看一眼就知道了,无非就是flex、order、flex-self,就这样记完了。

回到题目,重点使用 flex-shrink

这里一定要记住

item-div 中 ( flex-grow 和 flex-basis 是在有剩余空间使用 )( flex-shrink 是没有剩余空间使用 )

flex-basis 是在有剩余空间的时候才能自定义宽度,否则不起作用。

因此:

<style>
.perant{
backgrond:blue;
width:500px;
height: 300px;
display:flex;
margin:0 auto;
}
.child1{
background: red;
width: 300px;
height: 100%;
flex-shrink: 0; // 设置以后宽就是300px
}
.child2{
background: pink;
width: 200px;
height: 100%;
}
.child3{
background: green;
width: 100px;
height: 100%;
}
</style>
<body>
<div class="perant">
<div class="child1">1</div>
<div class="child2">2</div>
<div class="child3">3</div>
</div>
</body>

本文作者:轻风细雨_林木木

本文链接:https://www.cnblogs.com/linzhifen5/p/16961351.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   轻风细雨_林木木  阅读(163)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 尚好的青春 孙燕姿
  2. 2 孙燕姿
  3. 3 克卜勒 孙燕姿
- 孙燕姿
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.