css语法

css语法

两个主要的部分构成:选择器,以及一条或多条声明

 

 

 css注释

/*这是个注释*/

id 选择器

  #first {
            text-align:center;
            color:red;
        }
<div id="first">hello world</div>

class选择器

 .name {
            text-align:center;
            color:red;
        }
<div class="name">hello world</div>

标签选择器

 div {
            text-align:center;
            color:red;
        }
<div class="name">hello world</div>
<div class="name">hello world</div>

父元素下的子元素:子选择器

   div > div {
            text-align:center;
            color:red;
        }
<div class="name">
    <div >hello world</div>
    <div>hello world</div>
</div>

 

此外还有、通用选择器(*)包含选择器、兄弟选择器

外部样式表

1、链接式
<link type="text/css" rel="styleSheet"  href="CSS文件路径" />
2、导入式
<style type="text/css">
  @import url("css文件路径");
</style>

参考资料

https://www.runoob.com/css/css-howto.html

 

posted @ 2019-11-25 16:33  qijunL  阅读(95)  评论(0)    收藏  举报