html - 大于动态宽度父项时,弹性项目上的滚动条
问题描述
我有一个居中的 flexbox 结构,它显示带有客户列表的框。
我想实现,当屏幕变得比#box
div 内的内容窄时,它不会隐藏在视口之外,而是将溢出添加到最长的项目,它#list
与表格一起,因此#box
可以动态缩小。
width: 100%
当我添加但我不希望框全屏宽度时,它应该像它应该的那样工作,#box
直到它至少不是内容的大小。
body, html {
margin: 0;
width: 100%;
height: 100%;
font-size: 16px;
}
* {
box-sizing: border-box;
}
#wrap {
background-color: red;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 40px;
flex-direction: column;
}
#box {
background-color: #dcdcdc;
padding: 10px;
border-radius: 10px;
display: flex;
flex-direction: column;
/*width: 100%; this works, but dont want it full until box is equal or smaller than content*/
}
#box > div {
flex: 1 0 auto!important;
}
#title {
text-align: center;
margin-bottom: 20px;
font-size: 20px;
color: blue;
}
table {
border-spacing: 0;
border-collapse: collapse;
table-layout: auto;
white-space: nowrap;
width: 100%;
}
table thead {
font-weight: bold;
}
table tbody tr {
height: 30px;
}
table td {
padding: 0 5px;
}
#list {
overflow: auto;
background-color: rgba(0,0,0,0.05);
}
<div id="wrap">
<div id="box">
<div id="title">
List of customers
</div>
<div id="list">
<table>
<thead>
<tr>
<td>First name</td>
<td>Last name</td>
<td>Address</td>
<td>Telephone</td>
<td>Decription</td>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Smith</td>
<td>25th Jeffersons</td>
<td>555 2589654123</td>
<td>Pretty bad boy</td>
</tr>
<tr>
<td>Anna</td>
<td>Redford</td>
<td>Trading street 252</td>
<td>555 2541258745</td>
<td>Booty babe</td>
</tr>
<tr>
<td>Jack</td>
<td>Jackson</td>
<td>Dummy Dumm 55</td>
<td>555 123456789</td>
<td>Random persona</td>
</tr>
<tr>
<td>Buck</td>
<td>Buckson</td>
<td>Dummy Dumm 66</td>
<td>555 987654321</td>
<td>Another random persona</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
1 - 全屏窗口
2 - 调整大小(更小)的窗口
3 - 调整大小(更小)的窗口 - 想要的结果
解决方案
尝试添加而max-width: 100%;
不是- 它应该可以解决问题。width: 100%;
#box
推荐阅读
- reactjs - 反应:在提交时获取按钮的形式
- c++ - 为类模板中的成员函数定义单个模板,同时在成员函数中使用两个模板
- c# - 如何使用c#编辑excel行值
- firebase - Vuejs - Firebase/firestore 垃圾邮件网络请求
- kubernetes - 使用 REST_API 进行 Openshift 监控
- c# - 仅在 wpf 中的顶级项目之后将分隔符添加到 TreeView
- django - 我的第一个 django 应用程序 - 如何导入模板?
- git - Git:将两个分支之间的差异直接应用到master
- javascript - 在谷歌电子表格 GAS 的所需列中找到最后一个单元格
- vue.js - 如何删除 Vuex 状态数据