我有以下css:
.layout-main { display: flex flex-direction: column; }
如果我执行以下操作:
<div class="layout-main"> <div> stuff goes here </div> </div>
,
“东西”垂直居中。
但是,如果我定义了一个自定义元素,这将导致:
<div class="layout-main"> <my-element> <div> stuff goes here </div> </my-element> </div>
“东西”不是垂直居中的。
若我在.layout-main
上显式设置justify-content: center
,问题就解决了。
若我将display: contents
设置为my-element
,问题也解决了。
在contents
上看到了似乎相关的/docs
为什么自定义元素在display: flex; justify-content: center
父元素中没有像div那样垂直居中?