flex布局一行2块
时间: 2023-08-26 18:13:33 浏览: 88
在flex布局中,要实现一行显示两个块的效果,可以使用以下代码:
```
<div style="display: flex;">
<div class="item">块1</div>
<div class="item">块2</div>
</div>
<style>
.item {
flex: 1 1 50%; /* 设置每个块占据一半的空间 */
}
</style>
```
在这个例子中,我们使用了`display: flex;`将父容器设置为flex布局。然后,通过给每个块设置`flex: 1 1 50%;`,使得每个块占据父容器的一半空间。这样就能实现一行显示两个块的效果。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *3* [flex布局一行显示多个](https://blog.csdn.net/weixin_53472524/article/details/122163353)[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^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* [flex布局 一行显示三个 显示多行](https://blog.csdn.net/weixin_62009082/article/details/131611447)[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^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文