用 CSS 向表单输入中添加背景色


若要给表单输入添加背景色,请使用 background-color 属性。

可尝试运行以下代码,以便将背景色属性实现到表单

示例

实时演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         input[type=text] {
            width: 100%;
            padding: 10px 15px;
            margin: 5px 0;
            box-sizing: border-box;
            background-color: gray;
         }
      </style>
   </head>
   <body>
      <p>Fill the below form,</p>
      <form>
         <label for = "subject">Subject</label>
         <input type = "text" id = "subject" name = "sub">
         <label for = "student">Student</label>
         <input type = "text" id = "student" name = "stu">
      </form>
   </body>
</html>

更新时间:23-6 月 -2020

7K+ 浏览量

开启你的职业生涯

完成课程获得认证

开始
广告