【发布时间】:2021-07-02 08:04:36
【问题描述】:
我一直在尝试制作一个响应式表格,如果单元格宽度小于 200 像素,则该表格会折叠,问题是,一旦我折叠表格,单元格的宽度就会变成行的宽度。我知道我需要检查行宽是否大于列数* min-width (200px) 的总和。但是我不知道如何真正实现它,无论我尝试什么都会完全破坏它。
https://codepen.io/scottkane/pen/ExZvbvq
查看 codepen,将窗口变小以查看元素查询是否有效,然后尝试再次将窗口变大并查看它不会恢复样式。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Table</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/eqcss/1.9.2/EQCSS.min.js" integrity="sha512-yfw7F0e6Vqdxeg6nDlK4l4+pyBvwozVA61StkFRHcwW2dTAIRa4rfmvi4xXmcRmcnq4NI3jbOY4B8cc25n5SkA==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/eqcss/1.9.2/EQCSS-polyfills.min.js" integrity="sha512-Io6cpd8PlB4UY1JYCy1DzrfG+56EWKTXnwi+w9LdfrNiXaAkSI0EQTqRUO6YjMVqWQv6vF/zc4h0uumlPc1XPg==" crossorigin="anonymous"></script>
</head>
<body>
<style>
body {
font-family: "Open Sans", sans-serif;
line-height: 1.25;
}
.table {
color: #262626;
}
.table-head {
font-size: 0.85em;
font-weight: bold;
letter-spacing: 0.1em;
text-transform: uppercase;
border-bottom: 1px solid #838383;
}
.table-row {
height: auto;
display: flex;
gap: 10px;
padding: 0.75em;
border-top: 1px solid #838383;
}
.table-row > div {
text-align: center;
flex-basis: 100%;
}
@element .table-row > div and (max-width: 200px) {
.table-head {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0px;
position: absolute;
width: 1px;
}
.table-row {
border-bottom: 3px solid #ddd;
display: flex;
flex-wrap: wrap;
margin-bottom: 0.625em;
}
.table-row > div {
border-bottom: 1px solid #ddd;
display: block;
padding: 0.625em;
font-size: 0.8em;
text-align: right !important;
flex-basis: -1px;
flex-grow: 1;
}
.table-row > div::before {
content: attr(label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
.table-row > div:first-child {
padding-top: 0px;
}
.table-row > div:last-child {
border-bottom: 0px;
padding-bottom: 0px;
}
}
</style>
<div class="table">
<div class="table-row table-head">
<div>Account</div>
<div>Due Date</div>
<div>Amount</div>
<div>Period</div>
</div>
<div class="table-row">
<div label="Account">Visa - 3412</div>
<div label="Due Date">04/01/2016</div>
<div label="Amount">$1,190</div>
<div label="Period">03/01/2016 - 03/31/2016</div>
</div>
<div class="table-row">
<div label="Account">Visa - 6076</div>
<div label="Due Date">03/01/2016</div>
<div label="Amount">$2,443</div>
<div label="Period">02/01/2016 - 02/29/2016</div>
</div>
<div class="table-row">
<div label="Account">Corporate AMEX</div>
<div label="Due Date">03/01/2016</div>
<div label="Amount">$1,181</div>
<div label="Period">02/01/2016 - 02/29/2016</div>
</div>
<div class="table-row">
<div label="Acount">Visa - 3412</div>
<div label="Due Date">02/01/2016</div>
<div label="Amount">$842</div>
<div label="Period">01/01/2016 - 01/31/2016</div>
</div>
</div>
</body>
</html>
谢谢
【问题讨论】:
标签: html css responsive-design responsive