css - 带有 id 的表在 css 上不显示 td 和 tr 周围的边框
问题描述
我有一个 ID 为 #search_form 的表
当我写这个
table#search_form, tr#search_form, td#search_form, th#search_form {
height: 2em;
word-wrap: break-word;
border: 10px solid black;
}
它只显示表格周围的边框,而不是 tr、td 或 th 周围。
但是当我写这个时:
table, tr, td {
border: 10px solid black;
}
它也在 tr、td 周围的任何表格中显示边框。但我只希望在具有特定 ID 的表格上设置边框。
为什么它不起作用?
我试图在 css 中创建单独的块,例如 tr#search_form { .. } 但它也不起作用。
我试图删除逗号符号,删除 id 标签,但它不起作用。
为什么它会这样?
这是 HTML 表格:
<table id="search_form">
<form method = "get">
<tr>
<th>
<label>Search in file database </label>
<br><input type="search" name="query" placeholder="Search" maxlength="45">
<br><button type="submit" name="search" value="search">Search</button>
</th>
<td>
<label for="start">Start date range:</label>
<br><input type="date" id="from date" name="from-date"
value=""
min="2020-03-01" max="">
<br><label for="end">End date range:</label>
<br><input type="date" id="to date" name="to-date"
value=""
min="2020-03-01" max="">
</td>
<td>
</td>
</form>
<form method = "get">
<th>
<label>Tags search</label>
<br><input type="text" name="tags" data-role="tagsinput" placeholder="tag1,tag2,tag3">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
<br><button type="submit" name="search" value="tagssearch">Search</button>
</th>
<td>
<input type="checkbox" name="andcondition" value="1">
Check if you want each file to include all tags (AND condition)
</td>
</tr>
</form>
</table>
解决方案
以下代码仅在 id 为 search_form 的表格上放置边框,并在 th 和 td 子项周围放置边框:
#search_form {
height: 2em;
word-wrap: break-word;
border: 10px solid black;
}
#search_form th {
border: solid 5px black
}
#search_form td {
border: solid 5px black
}
小建议我会 kebab-case id 名称,因为这是 HTML 的约定。
那么你的 HTML 可能是:
<table id="search-form">
...
</table>
推荐阅读
- c# - 查询持久功能状态时 401 Unauthorized
- python - 如何对 Pandas Dataframe 中的行进行基本算术运算?
- c# - 如何以编程方式统一切片texture2d,就像我想将我的纹理分成两部分
- java - java.lang.UnsatisfiedLinkError: 无法获取类 com.sun.jna.Pointer (Neurotechnology Megamatcher SDK)
- android - 如何知道我使用的是哪个版本的 Google Play Developer API 版本?将 Google Play Developer API 版本更新到 v3 的步骤是什么?
- c# - 有没有办法为所有操作创建 CancellationToken 过滤器?
- c# - 如何从字符串的内容中填充对象并填充列表?
- scala - 对象 mockito 不是包 org 的成员
- appium - 为什么 uiautomatorviewer 无法截取音频修剪器的屏幕截图?
- reactjs - TypeError:无法读取未定义的属性“名称” - 反应测试