使用窗口调整表格和文本的大小
Resize table AND text inside with window
我正在尝试使用窗口大小重新调整表格及其文本的大小,最好只使用 html 和 css,但如果需要,可以尝试 js。我见过几个类似的例子,但没有一个完全符合我的情况。如果我需要重写表格来完成这项工作,我没有问题。
JSFiddle
<section id="scheduleInfo">
<h1 style="margin-bottom: 0px;"><a href="members_home.html" style="text-decoration: none;"><-Back</a></h1>
<h1 style="text-align:center;">Your Personalized Maintenance Schedule</h1>
<table class="schedule" border="1" summary="scheduleSummary" align="center">
<caption></caption>
<colgroup>
<col class="maintItem" />
<col class="maint1" />
<col class="maint2" />
<col class="maint3" />
<col class="maint4" />
<col class="maint5" />
<col class="maint6" />
<col class="maint7" />
<col class="maint8" />
<col class="maint9" />
<col class="maint10" />
</colgroup>
<thead id="maint">
<tr>
<th>Maintenance Item</th>
<th>March 2015 Maintenance</th>
<th>May 2015 Maintenance</th>
<th>August 2015 Maintenance</th>
<th>October 2015 Maintenance</th>
<th>December 2015 Maintenance</th>
<th>March 2016 Maintenance</th>
<th>May 2016 Maintenance</th>
<th>August 2016 Maintenance</th>
<th>October 2016 Maintenance</th>
<th>December 2016 Maintenance</th>
</tr>
</thead>
<tbody>
<tr>
<th>Pollen Filter</th>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
</tr>
<tr>
<th>Air Filter</th>
<td colspan="5"></td>
<td colspan="5"></td>
</tr>
<tr>
<th>Brake Flush</th>
<td colspan="5"></td>
<td colspan="5"></td>
</tr>
<tr>
<th>Transmission Flush</th>
<td colspan="10"></td>
</tr>
</tbody>
</table>
</section>
.CSS
table.schedule {
border: 4px solid rgba(166,206,57,.8);
border-radius: 6px;
border-collapse: collapse;
text-align: center;
width: 60%;
margin-bottom: 15px;
}
table.schedule thead {
background-color: white;
color: black;
font-family: 'Playball', cursive;
font-size: 110%;
border-bottom: 5px solid grey;
}
table.schedule td {
background: -webkit-linear-gradient(left, green, yellow, red);
}
table.schedule tbody th {
font-size: 150%;
padding-bottom: 15px;
padding-top: 15px;
}
table.schedule td {
border: 2px solid rgb(166, 206, 57);
}
table.schedule th {
padding: 0px 20px 0px;
}
如果您的浏览器支持媒体查询,则可以使用媒体查询。下面是一个示例,我使用它们来更改某些属性(但不是全部)。代码包含解释性注释。
<html>
<head>
<style>
/* values in here will apply when the browser width is 600px or less */
@media screen and (max-width: 600px) {
table.schedule tbody th {
font-size: 80%;
padding-bottom: 5px;
padding-top: 5px;
}
}
/* values in here will apply when the browser width is between 601px and 800px inclusive */
@media screen and (min-width:601px) and (max-width: 800px) {
table.schedule tbody th {
font-size: 150%;
padding-bottom: 15px;
padding-top: 15px;
}
}
/* remaining values will apply as normal */
table.schedule {
border: 4px solid rgba(166,206,57,.8);
border-radius: 6px;
border-collapse: collapse;
text-align: center;
width: 60%;
margin-bottom: 15px;
}
table.schedule thead {
background-color: white;
color: black;
font-family: 'Playball', cursive;
font-size: 110%;
border-bottom: 5px solid grey;
}
table.schedule td {
background: -webkit-linear-gradient(left, green, yellow, red);
}
table.schedule td {
border: 2px solid rgb(166, 206, 57);
}
table.schedule th {
padding: 0px 20px 0px;
}
</style>
</head>
<body>
<section id="scheduleInfo">
<h1 style="margin-bottom: 0px;"><a href="members_home.html" style="text-decoration: none;"><-Back</a></h1>
<h1 style="text-align:center;">Your Personalized Maintenance Schedule</h1>
<table class="schedule" border="1" summary="scheduleSummary" align="center">
<caption></caption>
<colgroup>
<col class="maintItem" />
<col class="maint1" />
<col class="maint2" />
<col class="maint3" />
<col class="maint4" />
<col class="maint5" />
<col class="maint6" />
<col class="maint7" />
<col class="maint8" />
<col class="maint9" />
<col class="maint10" />
</colgroup>
<thead id="maint">
<tr>
<th>Maintenance Item</th>
<th>March 2015 Maintenance</th>
<th>May 2015 Maintenance</th>
<th>August 2015 Maintenance</th>
<th>October 2015 Maintenance</th>
<th>December 2015 Maintenance</th>
<th>March 2016 Maintenance</th>
<th>May 2016 Maintenance</th>
<th>August 2016 Maintenance</th>
<th>October 2016 Maintenance</th>
<th>December 2016 Maintenance</th>
</tr>
</thead>
<tbody>
<tr>
<th>Pollen Filter</th>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
<td colspan="2"></td>
</tr>
<tr>
<th>Air Filter</th>
<td colspan="5"></td>
<td colspan="5"></td>
</tr>
<tr>
<th>Brake Flush</th>
<td colspan="5"></td>
<td colspan="5"></td>
</tr>
<tr>
<th>Transmission Flush</th>
<td colspan="10"></td>
</tr>
</tbody>
</table>
</section>
</body>
相关文章:
- 将HTML表格导出到带有文本和图像的excel中
- 如何将表格中的文本添加到使用按钮输入的文本区域
- 单击每个表格行中的复选框时启用文本框
- Mvc表格如何更改文本的颜色条件
- 设置“;将标签视为文本“;通过脚本将Google电子表格图表的值设置为true
- “搜索”文本仅考虑表格中的最后一列
- 在表格或所需位置下方弹出文本
- 与表格中的文本完美对齐
- 在输入字段之前提取表格单元格中的文本
- 循环通过表格查找第一个具有 CSS CSSstablelisttdselect 的 TD 文本
- 使用外部 javascript 更改多个表格单元格中的文本
- 是否可以使用 javascript 读取文本或电子表格文件
- JQuery 显示来自可见 HTML 表格单元格的文本的串联列表
- 如何使用JavaScript在HTML表格中获取td内部的链接文本
- jQuery将文本添加到放置在表格单元格中的图像中
- 如何防止 td 中的文本破坏表格的对齐方式
- 根据单元格内容更改表格行的文本颜色,仅使用 css
- 使用 javascript 将表格单元格中的文本制作到 URL
- 从 html 表格单元格中获取内容值,并使用 javascript 使其显示在文本框中
- 使用谷歌融合表格地图的网页文本/JavaScript未显示