弹性框项目的显示属性的使用 [英] Usage of display property of flex box items

查看:54
本文介绍了弹性框项目的显示属性的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改弹性框项目的显示属性是否有任何好处或理由?

Is there any benefit or reason to change display property of a flex box item?

尤其是,我对使用display:blockdisplay:inline-block

推荐答案

来自

弹性项目的显示值是 blockified :如果生成弹性容器的元素的流入子项的指定显示为内联级别值 ,它会计算为等效的块级. (有关此类显示值转换的详细信息,请参见CSS2.1§9.7[CSS21]和CSS Display [CSS3-DISPLAY].)

The display value of a flex item is blockified: if the specified display of an in-flow child of an element generating a flex container is an inline-level value, it computes to its block-level equivalent. (See CSS2.1§9.7 [CSS21] and CSS Display [CSS3-DISPLAY] for details on this type of display value conversion.)

因此,基本上,设置inline-blockblock不会做任何事情,因为两者都会被计算为block,但是您可以设置tableinline-table,并且flex项目将表现为表格.如果设置inline-gridgrid

So basically, setting inline-block or block will do nothing as both will get computed to block but you can set table or inline-table and your flex item will behave as a table. Same thing if you set inline-grid or grid

.box {
  display: flex;
  margin:5px;
}

.box>div {
  height: 50px;
  width: 100%;
  background: red;
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 1fr;
  grid-gap: 20px;
}

span {
  border: 2px solid green;
}

<div class="box">
  <div>
    <span></span>

    <span></span>
  </div>
</div>

<div class="box">
  <div style="display:inline-grid;">
    <span></span>

    <span></span>
  </div>
</div>

对于第二种情况,您可以看到它计算为grid

For the second case you can see it computes to grid

这篇关于弹性框项目的显示属性的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆