CSS——input(输入框)

  • input[type=text]

常规输入栏:

1. border-box将确保元素的总宽度和高度中包括内边距(填充)和最终的边框。

2. 点击后,会有默认效果

<!DOCTYPE html>
<html>
<head>
<style> 
input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}
</style>
</head>
<body>

<p>已填充的文本字段:</p>

<form>
  <label for="fname">First Name</label>
  <input type="text" id="fname" name="fname">
  <label for="lname">Last Name</label>
  <input type="text" id="lname" name="lname">
</form>

</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<style> 
input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
  border: 3px solid #ccc;
  -webkit-transition: 0.5s;
  transition: 0.5s;
  outline: none;
}

input[type=text]:focus {
  border: 3px solid #555;
}
</style>
</head>
<body>

<p>在本例中,我们使用了 :focus 选择器,在文本字段获得焦点时(被点击)为其添加黑色边框:</p>
<p>请注意,我们已添加 CSS 过渡属性以设置边框颜色的动画(改变颜色需 0.5 秒)。</p>

<form>
  <label for="fname">First Name</label>
  <input type="text" id="fname" name="fname" value="Bill">
  <label for="lname">Last Name</label>
  <input type="text" id="lname" name="lname" value="Gates">
</form>

</body>
</html>
  • input[type=password]

  • input[type=number]

  •  
posted @ 2022-10-14 17:30  新兵蛋Z  阅读(3533)  评论(0)    收藏  举报