javascript - CSS:在悬停时更改元素的背景:仅更改孩子的背景而不是父母的(小提琴,图片)
问题描述
我有这个代码:
html:
<div class="item">
<p>hello</p>
</div>
CSS:
.item {
border: 2px dashed green;
background-color: red;
width: 100px;
height: 100px;
margin-left: 30px;
margin-top: 30px;
}
.item :hover {
background-color: yellow;
}
我试图在悬停时将所有项目的颜色更改为黄色。但是,只有文本的背景颜色会发生变化:
虽然我想要这个:
解决方案
删除项目和悬停之间的空间
.item:hover {
background-color: yellow;
}
推荐阅读
- angular - getData 失败:发现不可调用的@@iterator angular ionic
- python - 如何在 Django 中使用 ListView 获取另一个用户的 object_list?
- python - PyTorch - 创建联合 CIFAR-10 数据集
- python - 如何将 blob 从 ( N , C , H , W ) 重塑为 ( N , H , W ,C )?
- c++ - 如何对数组中的连续整数进行分组?
- python - TypeError:“Mul”Op 的输入“y”的类型为 float32,与参数“x”的类型 int64 不匹配
- entity-framework-core - 使用 .Net Core 3.x 时是否应该升级到 EntityFrameWorkCore 5.x?
- java - 当Json文件具有相同的键值时如何使用HashMap
- sql-server - 将数据从 SQL Server 加载到 Elasticsearch
- php - 在 ProviderRepository.php 第 208 行:找不到类“Netshell\Paypal\PaypalServiceProvider”