html - CSS 颜色父行
问题描述
我是一名 CSS 初学者,我需要对包含<th>
具有特定 ID的单元格的 HTML 表格的一行进行着色
如何访问我的父元素th:id=yeah
以添加此 css 选项:background-color:red
<table style="width:100%">
<tr>
<th id="yeah">Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td id="one">Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
<style>
#one{
background-color: red
}
tr#yeah{
background-color: blue
}
table.class-name th:first-child {
background: red;
}
</style>
解决方案
you were so close!
your CSS:
tr#yeah{
background-color: blue;
}
Change:
#yeah{
background-color: blue;
}
Little thing to keep in mind. When styling elements in CSS you don't have to always include the TAG ( )
CSS knows you're styling a specific element by its Tag ID (#yeah) which is why you give your element a ID in html.
Good luck out there :D happy learning.
推荐阅读
- android-8.0-oreo - 关于 Android Oreo 构建的问题
- flutter - 用逗号分割用户输入地址
- python - 如何在下面的代码中正确使用 collate_fn?
- java - java.lang.ArrayIndexOutOfBoundsException 设置了简单数组
- angular - 映射复杂的 javascript 对象以制定内容类型为 x-www-form-urlencoded 的请求
- objective-c - 为什么 NStask 在启用 arc 的情况下泄漏内存?
- vue.js - Vuetify v-date-picker 无法正常工作
- html - 从内存中打开html页面
- styles - rsuite源码如何实现组件中的引用样式?
- javascript - 在 JavaScript 中修改后如何将字符串返回为原始格式