html - 为什么,标签高度内的元素没有增加?
问题描述
我正在尝试增加<td>
标签内元素的高度。但是,高度没有增加。
更具体地说,我希望<p>
标签内的<td>
标签具有 100% 的高度。
代码是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stack Overflow</title>
<!-- Local CSS -->
<style>
html,
body {
height: 100%;
width: 100%;
}
table {
height: 100%;
width: 100%;
}
td {
background-color: aqua;
}
input {
height: 100%;
width: 100%;
box-sizing: border-box;
}
p {
background-color: blueviolet;
display: inline-block;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th colspan="2"><input type="text" name="console" id="Console"></th>
</tr>
<tr>
<td>
<p onclick="one()">1</p>
</td>
<td>
<p onclick="two()">2</p>
</td>
</tr>
</table>
</body>
</html>
解决方案
在等待对我的评论的反馈时,这是一个网格布局示例,它可以执行您想要的操作,而无需指定height
为p
a 的直接子级grid
。
它还模仿了table-layout
没有副作用和额外标记的方法。
html,
body,
.border {
height: 100%;
width: 100%;
}
* {
box-sizing: border-box;
margin: 0;
}
.border,
.border p {
border: solid;
padding: 2px;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 1fr 2fr ; /* optionnal, here you can set heights for the rows */
grid-gap: 2px;
}
input {
height: 100%;
width: 100%;
}
p:first-of-type {
grid-column: span 2;
padding:0;
}
p {
background-color: blueviolet;
}
<div class="grid border">
<p>
<input type="text" name="console" id="Console">
</p>
<p onclick="one()">1</p>
<p onclick="two()">2</p>
</div>
这可能对您有用:https ://css-tricks.com/snippets/css/complete-guide-grid/ 和 https://gridbyexample.com/开始;)
推荐阅读
- reactjs - 创建客户端时无法连接到 twilsock
- android - 结合 Android 附近连接和视频
- .htaccess - .htaccess 代码使 url 小写并在需要时添加斜杠,有时会添加额外的斜杠。任何想法如何解决它?
- android - 如何通过在 Kotlin 中提供大小来创建数组
- android - 如何从图标中删除白色背景?
- css - 我可以使用 css 更改内联数据属性(数据视差)的值吗?
- google-chrome - 如何在观看视频时下载 Google Chrome 浏览器存储的 blob 数据?
- android - Android中的空对象引用
- java - 在给定的时间跨度上开始事件
- java - 如何提高效率