html - Hidden content in Chrome with Flexbox horizontally centered layout
问题描述
Based on this example i'm trying to center horizontally a content with flex css, and usually it goes right. But when the content is very large the left part goes hidden. It happens in Chrome, and the horizontal scrollbar doesn't help. As you can see in the snippet. What I have to change to get it right?
.flex-container {
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
.row {
width: auto;
border: 1px solid blue;
}
.flex-item {
background-color: tomato;
padding: 0px;
white-space: nowrap; /* added to simulate large content */
margin: 0px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: left;
}
<div class="flex-container">
<div class="row">
<div class="flex-item">hidden.............................somewhere.....................................................................................................end</div>
<div class="flex-item">where</div>
<div class="flex-item">I</div>
<div class="flex-item">am?</div>
</div>
</div>
As you can see, this is a different formulation of this problem with flexbox: here
解决方案
请尝试以下代码。
html, body {
height: 100%;
}
body {
margin: 0;
}
.flex-container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.row {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.flex-item {
background-color: tomato;
margin: 0px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: left;
max-width: 100%;
flex-grow: 1;
padding-right: 15px;
padding-left: 15px;
}
<div class="flex-container">
<div class="row">
<div class="flex-item">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="flex-item">where</div>
<div class="flex-item">I</div>
<div class="flex-item">am?</div>
</div>
</div>
推荐阅读
- android - 如何修复崩溃:Android 9 上的 ExoPlayer cast 扩展
- flutter - 在没有 mediasoup-client 的情况下使用来自 Flutter dart 客户端的 mediasoup 服务器
- scala - 在scala中的while循环中使用队列中的结果填充列表
- c++ - 静态分配对象的值初始化
- c - 尝试通过向量定义矩阵
- dijkstra - 如何使用图形工具获取从源到最大距离内所有点的距离(使用 Dijkstra 算法)
- android - 如何停止响应 Android 中的意图过滤器
- c# - 将 xlxs 转换为 csv 和数据格式
- python - Json 数据未显示在 HTML 页面 Python Flask 中
- c++ - 指向包含对齐 C 结构的 C++ 类的 C 指针的对齐问题