html - 想要内容以父级为中心,但要灵活包装
问题描述
我有以下标记(使用 Bootstrap 4):
.resource{
border:1px solid red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="resource">
<div class="container">
<div class="row justify-content-center">
<div class="wrapper d-flex flex-wrap justify-content-center">
<div class="card col-5">
<p>test1</p>
</div>
<div class="card col-5">
<p>test1</p>
</div>
<div class="card col-5">
<p>test1</p>
</div>
</div>
</div>
</div>
</div>
我希望卡片左对齐而不是居中。我可以通过justify-content-center
从 中删除来实现这一点.wrapper
,但随后.wrapper
不再居中.container
。
我怎样才能实现两者,使.wrapper
居中.container
并使.card
左对齐?
解决方案
你是什么意思?删除justify-content-center
不会影响.wrapper
in的位置.container > .row
。
包装纸仍然居中,卡片从左对齐。
但是如果要制作 2 列网格,则需要使用col-6
而不是,因为 Bootstrap 中的网格系统是以 12 为底而不是以 10 为底。col-5
.resource{
border:1px solid red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="resource">
<div class="container">
<div class="row justify-content-center">
<!-- removed "justify-content-center" -->
<div class="wrapper d-flex flex-wrap">
<!-- changed from "col-5" to "col-6" -->
<div class="card col-6">
<p>test1</p>
</div>
<div class="card col-6">
<p>test1</p>
</div>
<div class="card col-6">
<p>test1</p>
</div>
</div>
</div>
</div>
</div>
推荐阅读
- python - 如何修复 tkinter 按钮图像填充角落?
- html - 如何在行下创建带有小潜台词的可填充下划线文本
- azure-ad-b2c - 如何在强制更改密码时自定义登录流程重置密码
- ruby-on-rails - 在 Active Record 查询中包含 Active Storage 附件
- dependency-injection - 将类注册到特定实例
- python - 计算时间范围的最后一个值
- jquery - 从动态 json 数据渲染嵌套的 Bootsrap 手风琴
- python - 包含 c 字符串的 cython 类;缓冲区溢出?
- java - 我无法在我的设备上运行应用程序错误类型 3
- sql - Apache NiFi QueryRecord SELECT 静态别名列