html - CSS中输入的几个ID
问题描述
所以我想自定义几个输入。我试过这个,它工作正常:
<!DOCTYPE html>
<html>
<head>
<style>
input[id=a]:focus {
width: 250px;
}
</style>
</head>
<body>
<h1>The width Property</h1>
Searcha: <input type="text" name="search" id="a">
Searchb: <input type="text" name="search" id="b">
</body>
</html>
但是,我想在输入中添加更多 id。这是可能的?
//try
input[id=a b]:focus {
width: 250px;
}
解决方案
您可以像这样在 css 中链接选择器:
#foo, #bar {
color: red
}
但是,如果您有 >5 个 id,这可能会有点乏味,此时最好使用一个类:
HTML:
<input class="search-input" />
<input class="search-input" />
CSS:
.search-input {
color: red
}
推荐阅读
- java - 在附加页面上使用倒数计时器
- java - 如何获取 FirebaseListAdapter 中存在的元素数量?
- php - 如何使用嵌套的 do while 循环从数据库中获取菜单和子菜单?
- flutter - 为什么在从文本字段获取文本后尝试将文本发送到另一个页面时出现错误。我为此使用 bloc
- oracle - 为什么我得到 PLS-00049:Apex 中的绑定变量错误
- c++ - 在 C++ 中从输入文件中读取
- javafx - JavaFX 关键帧实例化
- android - 如何在真机上启动我自己的 admob 应用
- c# - 下载 csv 文件时出现问题,我已经创建它但无法在 asp.net 中下载
- c# - 如何在其他函数中更改我的全局变量?C#