[英]CSS : When to use display flex and display inline-block?
Hi, I have a scenario in which i want to make the above view. 嗨,我有一个想做以上观点的场景。 I am using
Bootstrap4
and I know I can achieve this by using either display:flex
or display:inline-block
. 我正在使用
Bootstrap4
,我知道可以通过使用display:flex
或display:inline-block
。 Now I really wanna know which to use when ? 现在我真的想知道何时使用哪个? What's the best practice ?
最佳做法是什么?
Right now i am doing something like this. 现在我正在做这样的事情。
.job-details-container { display: flex; } .job-details-container .job-details-type { width: 15% }
<div class="job-details-container"> <div class="job-details-type">Id</div> <div class="job-details-content">0234</div> </div>
Well, this is essentially a table. 好吧,这本质上是一张桌子。 So I suggest using HTML tables.
因此,我建议使用HTML表。 The cells will stretch automatically just like with
flex
. 像
flex
一样,单元格将自动拉伸。 Tables are fully supported back to IE 8. 从IE 8开始就完全支持表。
.job-details { border-collapse: collapse; width: 80%; margin: auto; } td, th { border-bottom: 1px solid #dddddd; text-align: left; padding: 10px; }
<table class="job-details"> <tr> <td>Id</td> <td>0234</td> </tr> <tr> <td>Service Type</td> <td>Move</td> </tr> <tr> <td>Schedule</td> <td>11:00 am, Jan 1, 2019</td> </tr> <tr> <td>...</td> <td>...</td> </tr> </table>
Change to flex
if you want to create layouts and complex designs. 如果要创建布局和复杂设计,请更改为
flex
。 For displaying simple text or maybe some images, tables are your friends. 对于显示简单文本或某些图像,表是您的朋友。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.