我是创建html表的新手,我已从各种资源中提取以创建以下内容以列出来自某些测试传感器的信息。
我正在努力做的是让全表自动扩展以填充用户浏览器窗口的大小。目前它是固定宽度。
必须添加到标题中以允许两列扩展/调整?
我目前的代码如下。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style type="text/css">
body {font-family: monospace; font-size: 13px; white-space: pre-wrap;}
</style>
</head>
<body>
<head> <meta http-equiv='refresh' content='30' /> </head><br/>
<style>.custom { font-size: 1em; font-family: Gill Sans Extrabold, sans-serif; padding:5px; border-collapse: collapse; border: 1px solid black; }
</style>
<table class=custom>
<tr class=custom>
<th class=custom>Security Sensor
</th>
<th class=custom>Last Tripped
</th>
</tr><br/>
<tr class=custom>
<td class=custom>20. Living Room
</td>
<td class=custom> 2018/04/09 - 11:47:52
</td>
</tr><br/>
<tr class=custom>
<td class=custom>18. Hallway
</td>
<td class=custom> 2018/04/09 - 11:47:17
</td>
</tr><br/>
<tr class=custom>
<td class=custom>10. Kitchen
</td>
<td class=custom> 2018/04/09 - 11:47:17
</td>
</tr><br/>
<tr class=custom>
<td class=custom>Kitchen - Motion Sensor
</td>
<td class=custom> 2018/04/09 - 11:39:41
</td>
</tr><br/>
<tr class=custom>
<td class=custom>17. Entrance Hall
</td>
<td class=custom> 2018/04/09 - 11:13:42
</td>
</tr><br/>lt;tr class=custom>
<td class=custom>05. Ben's Room
</td><td class=custom> 2018/04/09 - 11:13:26
</td>
</tr><br/>
<tr class=custom>
<td class=custom>02. Landing
</td>
<td class=custom> 2018/04/09 - 11:13:22
</td>
</tr><br/>
<tr class=custom>
<td class=custom>03. Loft Landing
</td>
<td class=custom> 2018/04/09 - 11:13:21
</td>
</tr><br/>
<tr class=custom>
<td class=custom>06. Loft Room
</td>
<td class=custom> 2018/04/09 - 11:13:14
</td>
</tr><br/>
<tr class=custom>
<td class=custom>01. Front Door
</td>
<td class=custom> 2018/04/09 - 10:38:47
</td>
</tr><br/>
<tr class=custom>
<td class=custom>08. Side Door
</td>
<td class=custom> 2018/04/09 - 10:36:04
</td>
</tr><br/>
<tr class=custom>
<td class=custom>13. Conservatory
</td>
<td class=custom> 2018/04/09 - 10:35:47
</td>
</tr><br/>
<tr class=custom>
<td class=custom>19. Front Room
</td>
<td class=custom> 2018/04/09 - 10:35:15
</td>
</tr><br/>
<tr class=custom>
<td class=custom>12. Dining Room
</td>
<td class=custom> 2018/04/09 - 10:34:36
</td>
</tr><br/>
<tr class=custom>
<td class=custom>07. Conservatory Door
</td>
<td class=custom> 2018/04/09 - 10:32:13
</td>
</tr><br/>
<tr class=custom>
<td class=custom>04. Main Bedroom
</td>
<td class=custom> 2018/04/09 - 10:23:57
</td>
</tr><br/>
<tr class=custom>
<td class=custom>09. Emma's Room</td>
<td class=custom> 2018/04/09 - 09:31:53
</td>
</tr><br/>
<tr class=custom>
<td class=custom>14. Kitchen Door
</td>
<td class=custom> 2018/04/08 - 16:21:20
</td>
</tr><br/>
<tr class=custom>
<td class=custom>11. Lean To</td>
<td class=custom> 2017/12/16 - 12:20:04
</td>
</tr><br/>
</table><br/>
</body>
</html>
答案 0 :(得分:1)
在类中或直接在表标记中给出宽度。您还可以在td标记中指定宽度,以便为表列提供宽度
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style type="text/css">
body {
font-family: monospace;
font-size: 13px;
white-space: pre-wrap;
}
.custom { font-size: 1em; font-family: Gill Sans Extrabold, sans-serif; padding:5px; border-collapse: collapse; border: 1px solid black; } table { width:100% } .th { width:50% }
</style>
</head>
<body>
<table class=custom>
<tr class=custom>
<th class=custom>Security Sensor</th>
<th class=custom>Last Tripped</th>
</tr>
<br/>
<tr class=custom>
<td class=custom>20. Living Room</td>
<td class=custom> 2018/04/09 - 11:47:52</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>18. Hallway</td>
<td class=custom> 2018/04/09 - 11:47:17</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>10. Kitchen</td>
<td class=custom> 2018/04/09 - 11:47:17</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>Kitchen - Motion Sensor</td>
<td class=custom> 2018/04/09 - 11:39:41</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>17. Entrance Hall</td>
<td class=custom> 2018/04/09 - 11:13:42</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>05. Ben's Room</td>
<td class=custom> 2018/04/09 - 11:13:26</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>02. Landing</td>
<td class=custom> 2018/04/09 - 11:13:22</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>03. Loft Landing</td>
<td class=custom> 2018/04/09 - 11:13:21</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>06. Loft Room</td>
<td class=custom> 2018/04/09 - 11:13:14</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>01. Front Door</td>
<td class=custom> 2018/04/09 - 10:38:47</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>08. Side Door</td>
<td class=custom> 2018/04/09 - 10:36:04</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>13. Conservatory</td>
<td class=custom> 2018/04/09 - 10:35:47</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>19. Front Room</td>
<td class=custom> 2018/04/09 - 10:35:15</td>
</tr>
<br/>
<tr class=custom>
<td class=custom>12. Dining Room</td>
<td class=custom> 2018/04/09 - 10:34:36</td>
</tr>
<br/>
</table>
</body>
</html>
答案 1 :(得分:0)
这将是必要的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<style type='text/css'>
table {
border: thin solid black;
width: auto;
height: auto;
}
</style>
</head>
<body>
<table>
<tr>
<td>
The table only expands enough for the content inside of it.
</td>
</tr>
</table>
</body>
</html>