css - 当第一个和第二个按钮之间有另一个元素时,如何使用 nth-child 正确选择第二个按钮?
问题描述
我试图使用
.myDivName button:nth-child(2) {
background-color: red;
}
选择我的第二个按钮,<div class="myDivName">
但它不起作用。我的代码是 -
<div class="myDivName">
<button>
1
</button>
<input type="text">
<button>
2
</button>
</div>
但我发现如果我删除了<input>
中间的,那么 nth-child 就可以了。
如何使用 nth-child(2) 正确选择此按钮?如果 nth-child 不能使用,最好的方法是什么?
谢谢!
解决方案
推荐阅读
- python - 由于 OSError 无法安装软件包:[WinError 5] Permission denied
- pandas - 聚合 pandas df 以获取 max 和 min 作为列
- google-api - HttpError 400 请求包含无效参数 Google API Campaign Manager - creatives().insert()
- javascript - PDFMAKE:在列表视图中单击按钮生成不同的 PDF
- javascript - PWA 服务工作者获取无法正常工作
- apollo - 基于 apollo 缓存中的键合并对象数组
- linux - 如何从另一个线程linux(c语言)停止在无限循环中工作的线程?
- flutter - Flutter:_route == ModalRoute.of(context)':在对话框中不正确
- matplotlib - 如何在 Matplotlib 中附加轴但不继承轴类型(Cartopy 类型,具体而言)
- r - 两个列表的元素乘法