gpt4 book ai didi

html - Overflow-X 不显示滚动条

转载 作者:行者123 更新时间:2023-11-28 00:28:34 27 4
gpt4 key购买 nike

我有一个用于放置表格的容器,我正在尝试应用 overflow-x 属性,但它出了点问题。我有一个可以工作的代码笔,我稍后会发布,但问题是它没有响应。当视口(viewport)靠近它时,它只是“粘住”(我真的无法解释得比这更好,尽管 Codepen 显示了它)。代码如下:

<section class='main-container'>
<h6>Users</h6>

<table>

<thead>
<tr>
<th class='name'>Name</th>
<th class='email'>Email</th>
<th class='role'>Role</th>
<th class='status'>Status</th>
<th class='alerts'>Alerts/Actions</th>
<th class='delete'></th>
</tr>
</thead>

<tbody>
<tr>
<td class='name'>Joe Bob</td>
<td class='email'>bobjoe@me.com</td>
<td class='role'>This is the role</td>
<td class='status'>Approved</td>
<td class='alerts'>There's an alert</td>
<td class='delete'></td>
</tr>
<tr>
<td class='name'>Joe Bob</td>
<td class='email'>bobjoe@me.com</td>
<td class='role'>This is the role</td>
<td class='status'>Approved</td>
<td class='alerts'>There's an alert</td>
<td class='delete'></td>
</tr>
<tr>
<td class='name'>Joe Bob</td>
<td class='email'>bobjoe@me.com</td>
<td class='role'>This is the role</td>
<td class='status'>Approved</td>
<td class='alerts'>There's an alert</td>
<td class='delete'></td>
</tr>
<tr>
<td class='name'>Joe Bob</td>
<td class='email'>bobjoe@me.com</td>
<td class='role'>This is the role</td>
<td class='status'>Approved</td>
<td class='alerts'>There's an alert</td>
<td class='delete'></td>
</tr>
<tr>
<td class='name'>Joe Bob</td>
<td class='email'>bobjoe@me.com</td>
<td class='role'>This is the role</td>
<td class='status'>Approved</td>
<td class='alerts'>There's an alert</td>
<td class='delete'></td>
</tr>

</tbody>

</table>

</section>

* {
box-sizing: border-box;
margin: 0;
padding: 0;
scroll-behavior: smooth;
border: none;
color: #425563;
-webkit-tap-highlight-color: transparent;
}

.main-container {

--away-left: 20px;
--border-radius: 2px;
--shine-brand-blue: #425563;
--shine-gray-two: #eceeef;
--shine-gray-one: #f1f2f3;

display: flex;
width: calc(100% - 80px);
max-width: 600px;
margin-right: 40px;
margin-left: 40px;
margin-top: 40px;
background-color: #fff;
border-radius: var(--border-radius);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2);
flex-flow: column nowrap;
justify-content: flex-start;
overflow-x: scroll;

h6 {
font-size: 16px;
height: 50px;
font-family: var(--main-font);
color: var(--shine-brand-blue);
line-height: 40px;
width: 100%;
border-bottom: 1px solid var(--shine-gray-two);
padding-left: var(--away-left);
display: flex;
align-items: center;
justify-content: flex-start;
}

table {
margin: 25px 0;
width: calc(100% - 40px);
margin-left: 20px;
margin-right: 20px;
border-collapse: collapse;

th, td {
text-align: left;
border-bottom: 1px solid #e0e3e5;
&.name {min-width: 149px;}
&.email {min-width: 230px;}
&.role {min-width: 148px;}
&.status {min-width: 82px;}
&.alerts {min-width: 195px;}
&.delete {min-width: 15px;}
}

th {
font-size: 10px;
font-weight: 500;
color: #7d8d9a;
text-transform: uppercase;
}

td {
font-size: 12px;
font-weight: 500;
line-height: 50px;
color: var(--shine-brand-blue);

select {
height: 40px;
width: 90%;
min-width: 140px;
border-radius: var(--border-radius);
background-color: var(--shine-gray-one);
cursor: pointer;
}

}

tbody tr {
transition: all .3s;

&:hover { background-color: #f5f6f7; }

}

}
}

main.next-to-aside {
position: absolute;
top: 60px;
right: 0px;
}

我怎样才能让表格做出响应而不是像它在这个 Codepen 中那样“固定”?: https://codepen.io/adammcgurk/pen/aXyZxm

最佳答案

所以我实际上不得不将表格包装在 div 中。仅使用 section 是行不通的,因为它包含的子项多于 table。所以样板代码如下所示:

<style>
.responsive-table {
overflow-x: scroll;
}
</style>

<section class='main-container'>
<!-- other content -->
<div class='responsive-table'>
<table>
<!-- table content -->
</table>
</div>
</section>

关于html - Overflow-X 不显示滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54525434/

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