CSS常用样式(id/class/元素选择器 用法)

目录

id选择器

 class选择器

元素选择器

完整代码


       在本篇文章之前,我有写过CSS样式表中的内联式与外链式的样式设置,需要了解的可以点进专栏里面学习。本篇文章主要是写id选择器、class类选择器以及元素选择器的用法介绍。 


id选择器

 首先我们在input这边设置一个id(id="ww")。

 <input id="ww" type="text" name="username" ><br>

其次在<head>里面将格式写出来,这边id引用的话需要在前面加上#字符。

 #ww{

            background-color: aqua;

        }


 class选择器

 首先也是选着想要调整的文本框,定义class(我这边是随意定义了一下class="class_w")

  <input class="class_w" type="number" name="age"><br>

其次在<head>里面将格式写出来,这边claa引用的话需要在前面加上英文格式的点(.)。

 .class_w{

            background-color: bisque;

        }


元素选择器

元素选择器不用再做设定,直接引用文章中的元素做设置。在这边我们以input为例做个简单文本框背景颜色设定,代码如下。

input{

            background-color: blueviolet;

        }

完整代码

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>表单</title>
<head>
    <style  type="text/css">
       
       label{
        cursor: pointer;
        display: inline-block;
        padding: 3px 6px;
        text-align: right;
        width: 150px;
        vertical-align: top;
            }
        #ww{
            background-color: aqua;
        }
        .class_w{
            background-color: bisque;
        }
        input{
            background-color: blueviolet;
        }
    </style>

</head>
<body>
    <div>
        <h1>Zoo Keeper Application Form</h1>
        <h4>Please complete the form Mandatory fields are marked with a</h4>
        <form  action="/test/url/">

        <fieldset >
            <legend>CONTACT DETAILS</legend>
            <label for="username">Name*</label>
            <input id="ww" type="text" name="username" ><br>

            <label >Telephone* </label>
            <input type="number" name="number" ><br>

            <label>  Email*</label>
             <input type="text" name="Email" ><br>
        </fieldset>

        <fieldset >
            <legend>PERSONAL INFORMATION</legend>
            <label> age</label>
            <input class="class_w" type="number" name="age"><br>

            <label>  Gender </label>
            <select >
                <option>one</option>
                <option>two</option>
                <option>three</option>
                <option>four</option>
            </select><br>  

            <label>When did you fist know you wanted to be a zoo_keeper</label>  
            <textarea cols="60" rows="6"></textarea>
        </fieldset><br>


        <fieldset >
            <legend>PICK YOUR FAVORITE ANIMALS</legend>
            <input type="checkbox" name="ANIMAL" value="Zebra">Zebra
            <input type="checkbox"name="ANIMAL" value="Cat">Cat
            <input type="checkbox"name="ANIMAL" value="Anaconda">Anaconda
            <input type="checkbox"name="ANIMAL" value="Human">Human<br>
            <input type="checkbox"name="ANIMAL" value="Elephant">Elephant
            <input type="checkbox"name="ANIMAL" value="Wildebeest">Wildebeest
            <input type="checkbox"name="ANIMAL" value="Pigeon">Pigeon
            <input type="checkbox"name="ANIMAL" value="Crab" >Crab<br>
        </fieldset>

            <input type="submit" value="注册">
        </form>

        </div>

</body>



</html>

 运行结果如下:

 

看到这里啦,如过觉得有用,点赞收藏再走,不然下回找不到啦。 比心

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五彩大铁猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值