因此,在尝试使用flexbox创建一个有用的模式时,我发现了什么似乎是一个浏览器问题,我想知道是否有一个已知的修复或解决方法 - 或者如何解决它的想法.
我想解决的问题有两个方面.首先,使模态窗口垂直居中,这可以按预期工作.第二个是让模态窗口滚动 - 外部,所以整个模态窗口滚动,而不是其中的内容(这样你就可以有下拉列表和其他可以扩展到模态边界之外的UI元素 - 像自定义日期选择器等)
但是,当将垂直居中与滚动条组合时,模态的顶部在开始溢出时可能无法进入.在上面的示例中,您可以调整大小以强制溢出,这样做可以让您滚动到模态的底部,但不能滚动到顶部(第一段被截断).
这是示例代码的链接(高度简化)
https://jsfiddle.net/dh9k18k0/2/
.modal-container {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
overflow-x: auto;
}
.modal-container .modal-window {
display: -ms-flexbox;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
// Optional support to confirm scroll behavior makes sense in IE10
//-ms-flex-direction: column;
//-ms-flex-align: center;
//-ms-flex-pack: center;
height: 100%;
}
.modal-container .modal-window .modal-content {
border: 1px solid #ccc;
border-radius: 4px;
background: #fff;
width: 100%;
max-width: 500px; …Run Code Online (Sandbox Code Playgroud) 我正在尝试布局li's使用flexbox.我把它们设置为列,li's每列3个.问题是我想要ul居中.
我正在ul使用中心align-content: center.当我这样做,并且有li's超过页面可以显示(溢出),li's在开始时被切断.(左侧的那些被切断,但右侧的那些显示正常.)
我不会有一个特定的数字li's,它可以在4到50之间.因此我无法删除align-content: center,因为当我有少量时li's,(比如4),结果不是我想要的.
如何在ul没有被切断的情况下居中?
html, body {
margin: 0;
height: 100%;
}
div {
align-items: center;
justify-content: center;
height: 100%;
display: flex;
overflow: auto;
background-color:aqua;
}
ul {
margin-top: auto;
margin-bottom: auto;
flex-direction: column;
width: 100%;
height: 70%;
padding: 0;
display: inline-flex;
flex-wrap: wrap;
align-content: center;
}
li {
flex-basis: calc(100% / …Run Code Online (Sandbox Code Playgroud)