CSS 基础知识(认识选择器)

时间:2017-04-16 20:10:56   收藏:0   阅读:286

定义:

语言特点:

CSS代码语法:

css样式由选择符声明组成,声明由属性组成,如图所示

技术分享

 选择符:又称选择器,指明网页中要应用样式规则的元素

 声明:在英文大括号{}中的的就是声明,属性和值之间用英文冒号分隔。当有多条声明时,中间可以英文分号“;”分隔。

 

 注释:CSS中也有注释语句:用/*注释语句*/来标明Html中使用<!--注释语句-->) ,即:ctrl+?

CSS中的基本样式:

            3种:内联式、嵌入式、外联式

 

<p style="color:red;font-size:12px">这是一个内联式。</p>

 

 

<style type="text/css">
span{
color:red;}</style>

 

 

 

 

<link href="text.css" rel="stylesheet" type="text/css" />

认识CSS中的选择器:

      标签选择器/元素选择器

  1. 标签选择器就是html代码中的标签,比如<html><body><h1><p><img><ul>

 

p{
   font-size: 20px;
}

 

      id 选择器

#box1{
   width: 50px;
   height: 50px;
   background-color:red;
}

      类选择器

 

 

 

.box1{
   width: 160px;
   height: 80px;
   background-color:rosybrown;
}

 

      属性选择器:

 

 

         对带有指定属性的 HTML 元素设置样式。

 

input[type="text"]
{
  width:150px;
  display:block;
  margin-bottom:10px;
  background-color:yellow;
  font-family: Verdana, Arial;
}

 

        后代选择器:后代选择器是作用于所有子后代元素

<p>这是一个<span>文档</p>

span{
   color: darkblue;
}

      分组选择器: 

/*同类兄弟第 第n个被选中*/
li:nth-child(7){
   background-color: pink;
}
/*同类兄弟倒数第n个选中*/
li:nth-last-child(7){
   background-color: blueviolet;
}
/*同类兄弟倒数第1个选中*/
li:first-child{
   background-color: aquamarine;
}
/*同类兄弟倒数最后1个选中*/
li:last-child{
   background-color: brown;
}
/*奇数项选中*/
li:nth-child(odd){
   background-color: darkblue;
}
/*偶数项*/
li:nth-child(even){
   background-color: coral;
}
/*_每。。。。一个循环,(_n从0开始,数字3可以随便更改—)—*/
li:nth-child(3n){
   background-color: darkred;
}

        子集选择器:子选择器是通过“>”进行选择。>作用于元素的第一代后代

ul>li{
   border: 1px d
   ashed red;
}

        并集选择器:同时选中所有标签,一并给予属性值

h1,h2,h3,h4,h5,h6{
   font-weight: normal;
}

       伪类选择器:允许给html不存在的标签(标签的某种状态)设置样式

/*a初始颜色/未被访问*/
a:link{
   color: red;
}
/*访问以后*/
a:visited{
   color:gold;
}
/*当鼠标悬停/移入*/
a:hover{
   color: blue;
}
/*点击时*/
a:active{
   font-size: 33px;
}

       伪元素:

 

/*________________伪元素____________*/
.pl:first-line{
   color: pink;
}
.pl:first-letter{
   font-size: 22px;
}
a:before{
   content: "请点击";     //a标签前面添加文字
}
a:after{
   content:  "嘿嘿";     //a标签后面添加文字
}

 

原文:http://www.cnblogs.com/lingzi940924/p/6719682.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!