就是在前端中,比如我有一个div盒子,里面包含其他的div和ul,这个div的class叫做info,我在样式里给这个div写上 display: flex;,请问它实现的范围是这个div盒子里变成弹性布局吗?如果我这个div盒子自己也想居中,那么是不是也得把这个div外面包围着它的,也变成弹性布局呢?一直理解不了这块,多谢了
4条回答 默认 最新
- 虎子8 2022-06-28 18:54关注
你说得是对的,动手验证一下即可,刚好今天写了一个示例,content 既是容器也是项目
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> html,body { padding: 0; margin: 0; height: 100%; } .root { display: flex; height: 100%; background-color: red; } .nav { width: 120px; background-color: blue; } .content { flex: 1; background-color: green; display: flex; align-items: center; justify-content: center; } .box { width: 120px; height: 120px; background-color: yellow; } </style> </head> <body> <div class="root"> <div class="nav"></div> <div class="content"> <div class="box">我是一个盒子</div> </div> </div> </body> </html>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录