我是靠谱客的博主 温婉鲜花,这篇文章主要介绍css基本的规则写法,现在分享给大家,希望可以做个参考。

1、基本样式 的写法

    

复制代码
1
2
3
4
5
<style type="text/css"> h1{ font-family:黑体; } </style>

直接些标签名进行定义属性,这个也比较常见。但是它的定义通常放在<style>标签中声明。

2、类class链接样式

定义也通常在<style>标签中声明

复制代码
1
2
3
4
5
6
<style type="text/css"> .style1{ color:red; font-size:16px; } </style>

引用时候直接在标签的属性中使用class="style1"  记住是class属性

<h1 class="style1"> </h1>

3、id链接样式

      

复制代码
1
2
3
4
5
6
<style type="text/css"> #style1{ color:blue; font-size:16px; } </style>

引用的时候就用标签属性中的id属性 ,要区别于类属性

<h1 id="style1"></h1>

区别:类class链接样式和id链接样式

类连接样式可以适用于多个对象设置同样的属性中,

而id链接样式只能用于一个对象标签中,其他标签则会失效

4、html选择器:

直接用标签进行声明,跟上面的第一个一样

2)派生选择器:

复制代码
1
2
3
4
5
6
7
<style type="text/css"> h1 h2{ color:red; font-size:1em; font-family:黑体; } </style>

h1 h2的写法意思是代表着该css样式只能之<h1><h2>  </h2></h1>同时出现,且是嵌套使用的时候才能生效

3)id选择器

id选择器的作用是通过id选择器将css样式作用到页面的对象上。写法:

复制代码
1
2
3
4
5
<style type="text/css"> #text p{ font-size:1em; } </style>

将该样式绑定到html上,就要这样写

<h1 id=#"text">这个是不要p的写法

要p的写法

表明该对象只能作用在text对象上的所有p标签中

4)class选择器

复制代码
1
2
3
4
5
6
<style type="text/css"> .fancy{ color:red; background:#666; } </style>

使用的时候也是

<h1 class="fancy"></h1>

也可以像上面的一样用派生选择器

复制代码
1
2
3
4
5
6
<style type="text/css"> .fancy td{ color:red; background:#666; } </style>

说明生效只能在td中

5)分组选择器

复制代码
1
2
3
h1{color:bule;} #text{color:bule;} .play{color:bule;}

这种写法太繁琐了

我们可以使用

复制代码
1
2
h1,#text,.paly{ color:bule;}

这样来定义

6)伪类和伪类选择器

用关键字:lang来定义

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
<html> <head> <style type="text/css"> q:lang(smile){ quotes:"∞" } </style> </head> <body> 好吧,展示一下 <p>请看<q lang="smile">祝你愉快</q></p> </body> </html>

 

最后

以上就是温婉鲜花最近收集整理的关于css基本的规则写法的全部内容,更多相关css基本内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部