博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS基础
阅读量:4309 次
发布时间:2019-06-06

本文共 1553 字,大约阅读时间需要 5 分钟。

CSS基础

一)简介

·CSS 指层叠样式表 (Cascading Style Sheets)
·样式定义如何显示 HTML 元素
·样式通常存储在样式表中
·把样式添加到 HTML 4.0 中,是为了解决内容与表现分离的问题
·外部样式表可以极大提高工作效率
·外部样式表通常存储在 CSS 文件中
·多个样式定义可层叠为一

二)语法

1)基本语法:选择器 { 属性: 值 } 

    body 
{
color
:
 blue
}
    p 
{
font-family
:
 "sans serif", arial, serif
;
}
    p 
{
text-align
:
center
;
 color
:
red
;
 padding
:
 1px 2px 3px 4px
;
}

2)选择器分组  

h1,h2,h2,h3,h5,h6 
{
color
:
 green
;
}

3)派生选择器

 li a 
{
color
:
 blue
;
}

4)id 选择器

   #id
{
color
:
 red
;
}
   #id a
{
color
:
 blue
;
}
    
<
id
="id"
>
color is red.
<
a
>
color is blue.
</
a
></
p
>

 

5)类选择器 

   .class{color: red;}
   .class a{color: blue;}
    
<
class
="class"
>
color is red.
<
a
>
color is blue.
</
a
></
p
>
    a.class {color: blue;}
    p.class {color: red;}
    
    
<
class
="normal"
>
normal a
</
a
><
br 
/>
    
<
class
="class"
>
blue a
</
a
>
    
<
class
="class"
>
red p
</
p
>

   

三)使用样式表

1)内部样式    
    
<
html
>
      
<
head
>
        
<
style 
type
="text/css"
>
          a.class 
{
color
:
 blue
;
}
          p.class 
{
color
:
 red
;
}
        
</
style
>
      
</
head
>
      
<
body
>
        
<
class
="normal"
>
normal a
</
a
><
br 
/>
        
<
class
="class"
>
blue a
</
a
>
        
<
class
="class"
>
red p
</
p
>
      
</
body
>
    
</
html
>
2)内联样式
    
<
html
>
    
<
head
>
    
</
head
>
    
<
body
>
      
<
style
="color: red;"
>
color p
</
p
>
    
</
body
>
    
</
html
>
3)外部样式
    
<
html
>
     
<
head
>
       
<
link 
rel
="stylesheet"
 type
="text/css"
 href
="mystyle.css"
 
/>
     
</
head
>
     
<
body
>
       
<
style
="color: red;"
>
color p
</
p
>
     
</
body
>
   
</
html
>
    mystyle.css
    p{color: red;}

当同一个 HTML 元素被不止一个样式定义时,样式的优先级由低到高排列如下:

    1:浏览器缺省设置
    2:外部样式表
    3:内部样式表(位于 <head> 标签内部)
    4:内联样式(在 HTML 元素内部)

转载于:https://www.cnblogs.com/JoeDZ/archive/2008/10/21/1316029.html

你可能感兴趣的文章
时序数据库InfluxDb
查看>>
C++ Knowledge series Conversion & Constructor & Destructor
查看>>
NodeJS学习笔记二
查看>>
JS把字符串转换为数字的方法
查看>>
hive的udf创建永久函数
查看>>
线段树标记永久化模板
查看>>
百度地图API显示多个标注点并添加百度样式检索窗口
查看>>
用户故事——老师
查看>>
sgen.exe" exited with code 1.解决方法
查看>>
实验一
查看>>
Ubuntu配置SSH免密码登陆
查看>>
SOA
查看>>
UVA10561 Treblecross 组合游戏/SG定理
查看>>
查询Oracle定时Job
查看>>
root账户不能使用密码只能使用密钥远程登陆
查看>>
浅谈WPF中对控件的位图特效(虚化效果、外辉光效果)
查看>>
[翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)...
查看>>
JavaWeb基础—会话管理之Cookie
查看>>
kettle学习笔记(六)——kettle转换步骤
查看>>
5、Node.js 回调函数
查看>>