html5--css

css样式:

1、内联样式:只针对当前标签。语法:<p style="属性:属性值"></p>

2、内部样式:只针对当前页面。语法:在head元素内部 <style> p{属性:属性值}</style>

3、外部样式:共享的css文件,需要引用一个外部css文件。在head内引入外部css文件 <link rel='stylesheet' type='text/css' href='css文件'>

优先级:内联-》内部-》外部

基础选择器【元素、类、ID】:

选择器声明:选择器{属性:属性值;...}

选择器分组:多个选择器共用相同样式,多个选择器之间用“,”隔开,如:p,h1,h2{属性:属性值}

元素选择器:如:p{属性:属性值}

类选择器:如:.list{属性:属性值}

id选择器:如: #id{属性:属性值}

注:合并使用选择器时用“,”隔开,如:.id,p{属性,:属性值},id选择器不能合并使用。

优先级:id->类->标签

派生与属性选择器:

<body>
<a href=""></a>
<a href="www.baidu.com"></a>
<ul>
    <li></li>
    <li><p></p></li>
</ul>
<ol>
    <li></li>
    <li><em></em></li>
</ol>
</body>

后代选择器:可选后代下任意一个后代,如:ul p{属性:属性值}

子元素选择器:只能找到某元素下的直接子元素,如:ul>li{属性:属性值}

相邻兄弟选择器:只能是同父级下相邻的元素,如:ul+ol{属性:属性值}

属性选择器:设置标签内属性,如:a[href]{属性:属性值},a[href="www.baidu.com"]{属性:属性值}

伪类

锚伪类【未被访问状态、已被访问状态、鼠标悬停状态、活动状态】:

<a href='#'></a>

:link 向未被访问的链接添加样式
:visited 向已被访问的链接添加样式
:hover 向鼠标悬停时链接添加样式
:active 向已被激活的元素添加样式【鼠标按下时】
<p><b>php</b></p>
<p></p>
<form>
    <input type='text' name=''>
</form>

:focus 向拥有键盘输入焦点的元素添加样式  input:focus{属性:属性值}
:first-child 向第一个子元素添加样式 p:first-child{属性:属性值}  p:first-child b{属性:属性值}

文本控制

color:设置文本颜色
direction:设置文本方向
line-height:设置行高
letter-spacing:设置字符间距
word-sapcing:设置字间距
text-indent:缩进首行文本
text-decoration:向文本添加修饰 underline:文字下划线 overline:文字上横线 line-through:文字中间横线
text-align:对齐元素中的文本
text-transform:控制元素中的字母  capitalize:文本内英文开头为大写  uppercase:文本内英文全大写 lowercase:文本内英文全小写

字体控制

font-family:属性定义文本的字体系列(通用系列:Serif,Sans-serif,Monospace,Cursive,Fantasy)
font-style:属性用来规定斜体文本(normal、italic、oblique)
font-weight:属性用来设置文本粗细(normal、bold、100~900)
font-size:属性用来设置文本的大小 (px/em/%)

背景控制

background-color:设置元素的背景颜色(color_name[red]/hex_name[#ff0000]/rbg_name[255,0,0])
background-image:为元素设置背景图像
background-repeat:设置是否平铺背景图像(repeat/repeat-x/repeat-y/no-repeat)
background-position:设置背景图像的位置(top,bottom,left,right,center/%/px)

列表控制

list-style-type:设置列表标记的类型(disc/none/circle/square/decimal[数字]..)
list-style-image:使用图像替换列表项的标记(list-style-image:url(图片路径))
list-style-position:设置在何处放置列表项标记
list-style:复合写法(list-style:url(图片路径) inside;)

链接控制

<head>
    a{color:'';font-size:'',text-decoration:none;font-family:'',font-weight:'';}<!--文本设置-->
    a:hover{属性:属性值}<!--伪类设置-->
</head>
<body>
    <a href="#">百度</a>
</body>

表格控制

boder-style:设置元素边框的样式(dotted solid double dashed..)
border-collapse:设置是否将表格边框折叠为单一边框(separate/collapse)
border-spacing:设置相邻单元格的边框间的距离(length length)
caption-side:设置表格标题的位置(top/bottom)

//表格中的对齐方式:
text-align:设置水平对齐方式(left/center/right)
vertical-align:设置垂直对齐方式(top/center/bottom)

border-style和border-collapse不能同时使用,否则看不出效果。

常见伪元素

:before--在元素之前添加内容  h1:before{content:''}
:after--在元素之后添加内容
:first-line--向文本的首行添加特殊样式
:first-letter--向文本的第一个字母添加特殊样式

盒模型【边框,内边距,外边距】

1、边框

在设置边框时,boder-style:solid需设置,否则边框没显示。

boder-style:用于设置元素所有边框的样式
border-width:为元素的所有边框设置宽度(thin/medium/thick/length)
border-color:设置四边边框的颜色 .class{border-style:solid;border-color:red}
border简写属性:用于将针对四边的属性设置在一个声明内 (boder:10px solid red)

2、内边距【首先覆盖系统内边距,*{padding:0px}】

padding-top:设置内边距上边距
padding-left:设置内边距左边距
padding-right:设置内边右边距
padding-bottom:设置内边距下边距

3、外边距【声明:*{padding:0px;margin:0px}】

margin是简写属性可以一个声明中设置所有外边距属性(auto/length/%)该属性可以有1到4个值
如:p{border:1px solid red;margin:20px}

 

 

 

 

 


版权声明:本文为qq_42176520原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。