CSS基本语法和选择器
来源:互联网 发布:淘宝联盟 退运费 福袋 编辑:程序博客网 时间:2024/04/26 14:15
CSS是指层叠样式表(cascading style sheets),样式定义如何显示HTML元素,是真正能够做到网页表现和内容分类的一种语言。
【1】CSS基本语法
【2】CSS两种结合方式
【3】几种选择器
基本语法
基本语法也就两种,在head中使用选择器选择,然后在body中使用,如下中的样式属性键:样式属性值1 样式属性值2...是多个属性值的连用。
<!DOCTYPE html><html> <head> <title>02-结合方式2.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--><!-- 语法1:选择器{样式属性键: 样式属性值;样式属性键:样式属性值1 样式属性值2 样式属性值3...;/* 注释内容!*/ 语法2:style="样式属性键: 样式属性值;"} --> <style type="text/css"> p{ color:red; } </style> </head> <body> <p > This is my HTML page. </p> </body></html>
<!DOCTYPE html><html> <head> <title>01-结合方式1.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--下面是第二种结合方式--> <style type="text/css"> p{ color:blue; } </style> </head> <body> <p style="color:red;" > 我是在body中直接使用的结合方式 </p> <p> 我是使用表标签选择器的结合方式了</p> </body></html>
标签选择器
使用的是html的标签,比如p、h1、a等,也可以是html
<span style="font-size:18px;"><!DOCTYPE html><html> <head> <title>02-结合方式2.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- 标签选择器:标签名称{}} --> <style type="text/css"> a{ color:blue; background:red; padding:99; } p{ color:#FFFF00; } </style> </head> <body> <a> This is my HTML page. </a> <p> This is my HTML page. </p> </body></html></span>
ID选择器
以一种独立于文档元素的方式来指定样式
<!DOCTYPE html><html> <head> <title>06-CSS选择器2.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- id选择器:#标签id{}注意: 使用id时.要保证id的值在页面中是唯一的 --> <style type="text/css"> #one{ color:yellow; } #five{ size:88; } </style> </head> <body> <a id="one" > This is my HTML page. </a><br> <a id="five" > This is just a test. </a><br> <a> This is my HTML page. </a> </body></html>
其实类选择器是和ID选择器想类似的
<!DOCTYPE html><html> <head> <title>07-CSS选择器3.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- class选择器:.class名称{}注意: 使用class选择器,前面要有一个.号 --> <style type="text/css"> .three{ color:green; } </style> </head> <body> <p>This is my HTML page.</p> <p class="three" >This is my HTML page.</p> <a class="three" > This is my HTML page. </a><br> <a> This is my HTML page. </a> </body></html>
这个可以控制标签的的某些状态,配合其他选择器来共同使用
<!DOCTYPE html><html> <head> <title>07-CSS选择器3.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- 伪类选择器:选择标签的某个状态.需要配合其他选择器来使用l link<span style="white-space:pre"></span>未访问过v visited访问过h hover<span style="white-space:pre"></span>悬浮a active激活,点击 --> <style type="text/css"> a:link{ color:green; } a:visited{ color:black; } a:hover{ color:white; } a:active{ color:pink; } </style> </head> <body> <a href="01-结合方式1.html" >点我,看我的状态变化</a> </body></html>
将ID、类、元素结合在一起来使用,可以看到在body中是分开使用的,在style中是结合在一起的。
<!DOCTYPE html><html> <head> <title>09-CSS选择器5.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style type="text/css"> #one,.two,font{ color:green; } </style> </head> <body> <a id="one" >我是ID选择器</a><br> <a class="two" >我是类选择器</a><br> <font>我是元素选择器</font> </body></html>
2 0
- CSS基本语法和选择器
- CSS语法结构和选择器
- jQuery基本语法和选择器
- CSS:基本语法及派生选择器
- CSS的基本选择器和扩展选择器
- CSS基本选择器和优先级
- HTML学习之Css基本语法、样式表和选择器的初步认识
- css选择器-基本选择器
- CSS的语法、类和id选择器
- Css基本语法和引用
- CSS 基本语法和高级语法
- CSS基础:基本选择器分类和使用
- H5基本样式和css选择器
- CSS的基本选择器和优先级
- CSS语法及选择器
- css语法--选择器
- 06-DIV+CSS-CSS的必要性和基本选择器
- 基本CSS选择器,复合选择器,后代选择器
- Python urllib2实例代码演示
- Spring源码解析——从XmlBeanFactory的构造函数开始看LoadBeanDefinitions
- WDF DMA 一些概念(一)
- 相对路径与绝对路径以及斜杠与反斜杠的区别
- jsp中实现带滚动条的table表格
- CSS基本语法和选择器
- hive
- 内部类访问外部类的属性的原理
- 获得当前选择的控制器
- 求mat的连通域,并只显示最大轮廓的连通域
- Android 定义全局LOG打印日志,并显示调用者相关信息
- uva191 Intersection(线段之间相交)
- 直接量
- 监听通知,在程序退出前要移除