css - 为什么使用Flexbox时overflow-x会使块的宽度发生变化?
问题描述
考虑以下代码段:
.page-wrapper {
border: 2px solid blue;
padding: 5px;
width: 700px;
/* I'm using flexbox here */
display: flex;
justify-content: center;
}
.container {
border: 5px solid red;
padding: 10px;
/*
Changing overflow-x, the box width will change:
hidden --> width is 700px
visible --> width is 3000px
*/
overflow-x: hidden;
}
.content {
background-color: orange;
width: 3000px;
height: 100px;
}
<div class="page-wrapper">
<div class="container">
<div class="content">
</div>
</div>
</div>
与overflow-x: hidden
:
与overflow-x: visible
:
为什么更改overflow-x
容器元素的属性,容器框的宽度会发生变化?
解决方案
根据定义 overflow-x
属性visible
是内容不被裁剪,可能会渲染到左右边缘之外。这是默认设置。我认为您应该尝试使用滚动
.page-wrapper {
border: 2px solid blue;
padding: 5px;
width: 700px;
/* I'm using flexbox here */
display: flex;
justify-content: center;
}
.container {
display: block;
border: 5px solid red;
padding: 10px;
/*
Changing overflow-x, the box width will change:
hidden --> width is 700px
visible --> width is 3000px
*/
overflow-x: scroll;
}
.content {
background-color: orange;
width: 3000px;
height: 100px;
}
<div class="page-wrapper">
<div class="container">
<div class="content">
</div>
</div>
</div>
推荐阅读
- javascript - 遍历javaScript中条件&&语句中的数组?
- grails - 包含 GEB 测试时,Grails 3 integrationTest“未找到当前线程的会话”
- excel - 多列验证,1列比较
- android - 图片上传不适用于 WKWebView 但适用于 SFSafariViewController
- node.js - 如何使用真实的 url 而不是 localhost 使 api 休息
- c - 创建匿名结构的 typedef 有什么意义?
- element-ui - 在 element-ui 传输组件中使用 render-content 属性进行自定义渲染不起作用
- angular - Angular7 - [ngModel] 不会在组件中更新,当两次输入相同的值时
- r - 更了解 reshape() 函数
- xcode - iTunes Store 操作失败。下载的软件组件已损坏,将无法使用