html - HTML表单中文本输入类型的CSS不起作用
问题描述
我有以下用于 HTML 表单的 CSS:
input[type=text], input[type=password] {
transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
padding: 18px;
height: 20px;
width: 150px;
border-bottom: 2px solid #FFD800;
border-top: 0px;
border-right: 0px;
border-left: 0px;
background-color: #E2E2E2;
color: dimgray;
}
input[type=text], input[type=password]:focus {
height: 30px;
width: 200px;
animation-name: smooth;
background-color: #FFD800;
animation-duration: 0.5s;
animation: smooth 0.5s forwards;
color: black;
}
<div class="body">
<form action="" autocomplete="off" method="POST">
<br><br><h2 align="center">Login</h2><br>
<input type="text" placeholder="Username" name="Username"><br><br>
<input type="password" placeholder="Password" name="Password"><br><br>
<input type="submit" value="submit" name="submit">
</form>
</div>
但是,只有该password
字段看起来应如此。
请指教。谢谢你。
解决方案
欢迎来到 Stack Overflow 和很棒的第一个问题,包括代码。
专注于文本输入时,您缺少添加样式的:focus
方法。input[type=text]
改变
input[type=text],
input[type=password]:focus
至
input[type=text]:focus,
input[type=password]:focus
它会起作用。
工作示例:
input[type=text],
input[type=password] {
transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
padding: 18px;
height: 20px;
width: 150px;
border-bottom: 2px solid #FFD800;
border-top: 0px;
border-right: 0px;
border-left: 0px;
background-color: #E2E2E2;
color: dimgray;
}
input[type=text]:focus,
input[type=password]:focus {
height: 30px;
width: 200px;
animation-name: smooth;
background-color: #FFD800;
animation-duration: 0.5s;
animation: smooth 0.5s forwards;
color: black;
}
<div class="body">
<form action="" autocomplete="off" method="POST">
<br><br>
<h2 align="center">Login</h2><br>
<input type="text" placeholder="Username" name="Username"><br><br>
<input type="password" placeholder="Password" name="Password"><br><br>
<input type="submit" value="submit" name="submit">
</form>
</div>
推荐阅读
- node.js - 如何强制 npm 使用 https 节点存储库
- java - 当 URL 有“+”时 JarURLConnection.connect 抛出 java.io.FileNotFoundException
- python - 从编辑的 PyQt5 QTableView 对象中保存更新的数据框
- grep - 如何从 Gitlab ci 脚本中的 kotlin-dsl Gradle 文件中获取 versionName/versionCode?
- tfs - WiX 引导程序 UI 未从 TFS 构建定义编译
- r - 根据表达式的字符数组改变数据框的列?
- c - 在 c 中重新分配 char** 数组(Seg 故障核心转储)
- git - Intellij IDEA - 如何理解哪个项目连接到 github 并且可以推送,哪些不能推送 - 只是本地 git?
- mysql - 如何按另一行值对表结果排序
- r - 嵌套函数中的 Quosure