Flexbox的柱对齐项相同的宽度但不居中包装物(CSS-只)
这是一个移动菜单,这当然需要是响应。
的最长孩子应设置宽度为所有其他的孩子
.index
需求是全宽度和高度与背景色。
只有 CSS,请
我想解决这个问题没有额外的包装。
我的代码:
.index {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column; /* main-axis vertical */
justify-content: center; /* main-axis alignment */
align-items: center; /* neither center nor stretch produce desired result */
}
.index a {
/* nothing important here */
}
<div class="index">
<a href="">Some item</a>
<a href="">Some other item</a>
<a href="">This one long item</a>
<a href="">Overview</a>
<a href="">Contact</a>
</div>
我试过到目前为止:
- 满额填充在任父(
.index
)或儿童(a
)从来没有全包为中心的完美 - 与物品最大宽度玩耍了,但...
我想解决这个问题没有一个额外的包装。
在过去的几个月中,我发现有很多关于原生Flexbox行为的东西,我想知道并希望它能处理这个用例。
您是否尝试过使用'填充“属性y? – Roy123
正如我指出的,我试图在父'.index'和孩子'a'上填充,并且从未跨多个视口宽度获得整个框的完全居中对齐。但我可能是错的。 –
基本上,没有包装的Flexbox是不可能的。 –