html - Html and CSS: Unable to Change Background Color of Container
问题描述
I am trying to change the background color of the header where it says className="NetworkListHeader"
, but the color is not changing. I want the top portion of the container to be a different color than the body of the container.
HTML code:
class UserNetwork extends Component{
render(){
return(
<div className="UserNetworkContainer">
<div className="NetworkListHeader">
<h2>Your Network</h2>
</div>
<div><li>Object 1</li></div>
<div><li>Object 2</li></div>
<div><li>Object 3</li></div>
</div>
)
}
};
export default UserNetwork;
CSS code:
.UserNetworkContainer{
padding: 10px;
position: absolute;
border-radius: 7px;
top:23%;
right: 73%;
width:23%;
height: 50%;
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.1), 0px 1px 12px 1px rgba(0, 0, 0, 0.17);
}
.NetworkListHeader{
width: 100%;
font-family: Arial, Helvetica, sans-serif;
color: #2C3E50;
font-size: 15px;
margin-left: 70px;
margin-top: 16px;
background-color: blue;
}
解决方案
标头位于 that 内的h2
标签中div
,因此请将此选择器用于您的 CSS 规则:
.NetworkListHeader > h2 {
width: 100%;
font-family: Arial, Helvetica, sans-serif;
color: #2C3E50;
font-size: 15px;
margin-left: 70px;
margin-top: 16px;
background-color: blue;
}
推荐阅读
- excel - 用 VBA excel 交换行
- python - 将 .py 转换为 .exe 后,Selenium webdriver 无法正常工作
- excel - 将字符串保存到 VBA 中未初始化的 Variant 变量中
- google-chrome-extension - 单击按钮时打开从 popup.html 打开的相同窗口
- firebase - 无法从方法“_userFromFirebaseUser”返回“用户”类型的值
- ruby - Rspec - 使用模拟回溯创建 StandardError 实例
- c++ - 如何在 C++ 中删除三角形之间的间距?
- c# - 如何从 datagridview 控件中的数据库中获取所选行的 id?
- python - 从python如何拆分列表中的“:”行
- android - Kotlin Retrofit response.body() 在 arrayList 上返回 null