选择器

2018.1.8

选择器

1,标签选择器,用标签名做选择器。

<style type="text/css">
p//格式对p标签起作用
{样式}
</style>

2,class选择器。都是“.”开头

</head>
    <style type="text/css">
    .main   /*定义样式*/
    {
        height:42px;
        widows:100%
        text-align:center    
        }
    </style>
</head>
<body>
    <div class="maim">     <!--调用class样式-->

    </div>
</body>

3,ID选择器。以#开头

<div id="样式名">

</head>
    <style type="text/css">
    #main   /*定义样式*/
    {
        height:42px;
        widows:100%
        text-align:center    
        }
    </style>
</head>
<body>
    <div class="maim">     <!--调用class样式-->

    </div>
</body>

4,复合选择器。

a。用“,”隔开,表示并列。

<style type="text/css">
    p, span   /*标签p,span两者同样的样式*/
    {
        样式
        }
    </style>

b。用空格隔开,表示后代。

<style type="text/css">
.main p /*找到使用样式“main”的标签,在该标签里的p标签使用该样式*/
{
样式
}
</style>

c。筛选“.”

<style type="text/css">
    p,sp   /*在标签p中的 class="sp"的标签,执行以下样式*/
    {
        样式
        }
    </style>
原文地址:https://www.cnblogs.com/sgb13527/p/8267563.html