display flex 父元素宽度变窄
时间: 2023-08-24 20:15:40 浏览: 185
纯CSS让子元素突破父元素的宽度限制
回答: 当使用display:flex时,父元素的宽度可能会变窄。这可能是由于子元素的flex-shrink属性设置不当导致的。为了解决这个问题,可以在子元素中添加flex-shrink:0;的样式,并为子元素设置适当的宽度。例如,可以使用以下代码来解决这个问题:
```css
.fartherCss{
display: flex;
}
.sonCss{
flex-shrink: 0;
width: 30px;
}
```
这样子元素就不会随着父元素的宽度变窄而缩小了。\[1\]
#### 引用[.reference_title]
- *1* [设置display的影响](https://blog.csdn.net/Smile_666666/article/details/124056934)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [flex布局子元素不溢出不变形的探讨](https://blog.csdn.net/weixin_44634727/article/details/122058822)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文