gpt4 book ai didi

css - 我如何让一个div在屏幕上水平增长

转载 作者:行者123 更新时间:2023-11-27 23:49:17 25 4
gpt4 key购买 nike

我有一个包含表格的布局。如果表格包含的数据足够宽,可以离开屏幕,我希望包含表格的 div 水平增长。当数据垂直而非水平离开屏幕时,它目前有效。这是代码:

#main-content {
display: flex;
background-color: lightblue;
}
#field-selection-area {
flex-shrink: 0;
border: 1px #AAAAAA solid;
background-color: aliceblue;
}
#field-selection-area ul {
list-style: none;
padding: 4px;
margin: 0;
}
#field-table-area {
border-right: 1px #AAAAAA solid;
border-bottom: 1px #AAAAAA solid;
}
.field-area {
border-top: 1px #AAAAAA solid;
padding: 4px;
}
#table-area {
border-top: 1px #AAAAAA solid;
}
#table-area table td {
border: 1px #AAAAAA solid;
}
<div id="main-content">
<div id="field-selection-area">
<ul class="no-text-selection">
<li>Period</li>
<li>Market</li>
<li>Trade ID</li>
</ul>
</div>

<div id="field-table-area">
<div id="field-config-area">
<div id="filter-field-area" class="no-text-selection field-area">
Drop Filter Fields Here
</div>

<div id="row-field-area" class="no-text-selection field-area">
Drop Row Fields Here
</div>

<div id="column-field-area" class="no-text-selection field-area">
Drop Column Fields Here
</div>
</div>

<div id="table-area">
<table>
<tr>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
</tr>
</table>
</div>
</div>
</div>

当屏幕足够宽时,这是有效的:

Working when screen is wide enough但是,如果我调整屏幕大小然后滚动,就会发生这种情况:

Not working when screen size too small在上图中,我稍微向右滚动。我希望该表被完全包含。有人知道怎么做吗?

最佳答案

你可以在你的表格区域使用 overflow: auto:

#table-area{
border-top: 1px #AAAAAA solid;
overflow:auto;
}

演示:

#main-content{
display: flex;
background-color: lightblue;
}

#field-selection-area{
flex-shrink: 0;
border: 1px #AAAAAA solid;
background-color: aliceblue;
}

#field-selection-area ul{
list-style: none;
padding: 4px;
margin: 0;
}

#field-table-area{
border-right: 1px #AAAAAA solid;
border-bottom: 1px #AAAAAA solid;
}

.field-area {
border-top: 1px #AAAAAA solid;
padding: 4px;
}

#table-area{
border-top: 1px #AAAAAA solid;
overflow:auto;
}

#table-area table td{
border: 1px #AAAAAA solid;
}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Pivot Web</title>
<link rel="stylesheet" href="style2.css">
</head>
<body>

<div id="main-content">
<div id="field-selection-area">
<ul class="no-text-selection">
<li>Period</li>
<li>Market</li>
<li>Trade ID</li>
</ul>
</div>

<div id="field-table-area">
<div id="field-config-area">
<div id="filter-field-area" class="no-text-selection field-area">
Drop Filter Fields Here
</div>

<div id="row-field-area" class="no-text-selection field-area">
Drop Row Fields Here
</div>

<div id="column-field-area" class="no-text-selection field-area">
Drop Column Fields Here
</div>
</div>

<div id="table-area">
<table>
<tr>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
<td>18.0</td>
</tr>
</table>
</div>
</div>
</div>

</body>
</html>

关于css - 我如何让一个div在屏幕上水平增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28152593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com