
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>在标签的style属性上设置CSS样式title>
- head>
- <body>
- <div style="width:300px;height:100px;background-color:beige">hello,北京div>
- <br/>
- <div style="width:300px;height:100px;background-color:beige">hello,上海div>
- <br/>
- <div style="width:300px;height:100px;background-color:beige">hello,天津div>
- <br/>
- body>
- html>
问题分析
*标签多了,样式多了,代码量庞大
*可读性差
*CSS代码没有复用性

- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>在head标签中,使用style标签来定义需要的CSS样式title>
- <style type="text/css">
- div{
- width:300px;
- height:100px;
- background-color: beige;
- }
- span{
- border:1px solid red;
- }
- style>
- head>
- <body>
- <div>hello,北京div>
- <br/>
- <div>hello,上海div>
- <br/>
- <span>hello,spanspan>
- body>
- html>
问题分析
*只能在同一页面内复用代码维护不方便
*实际项目中会有很多页面,需要到对应页面去修改。工作量大
- div{
- width:200px;
- height:100px;
- background-color:brown;
- }
- span{
- border:2px dashed blue;
- }
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>把CSS样式写成单独的CSS文件,再通过link标签引入title>
-
- <link rel="stylesheet"type="text/css"href="./CSS/mycss.css">
- head>
- <body>
- <div>hello,北京div>
- <br/>
- <div>hello,上海div>
- <br/>
- <span>hello,spanspan>
- body>
- html>
1.最常见的CSS选择器是元素选择器。换句话来说,文档的元素就是最基本的选择器
2.CSS元素/标签选择器通常是某个HTML元素,比如p、h1、a div等
3.比如:

4.应用实例

- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>元素选择器title>
-
- <style type="text/css">
- h1{
- color:beige;
- }
- p{
- color:blue;
- }
- style>
- head>
- <body>
- <h1>夏目友人帐h1>
- <p>hello,worldp>
- body>
- html>
1.id选择器可以为标有特定id的HTML元素指定特定的样式
2.id选择器以“#”来定义
3.比如:

4.应用实例 id-selector.html

- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>id 选择器title>
-
- <style type="text/css">
- #xmyrz{
- color:gold;
- }
- #css1{
- color:green;
- }
- style>
- head>
- <body>
- <h1 id="xmyrz">夏目友人帐h1>
- <p id="css1">hello,worldp>
- body>
- html>
1.class类选择器,可以通过class属性选择去使用这个样式
2.基本语法
![]()
3.应用实例 class-selector.html

- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>类选择器title>
-
- <style type="text/css">
- .class01{
- color:red;
- }
- .class02{
- color:sandybrown;
- }
- style>
- head>
- <body>
- <div class="class01">韩顺平教育div>
- <p class="class02">hello,worldp>
- body>
- html>
1.组合选择器可以让多个选择器共用同一个css样式代码
2.语法格式

3.应用实例 all-seletor.html

- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>组合选择器title>
- <style type="text/css">
- /*
- 组合选择器
- 选择器1,选择器2,选择器n{属性:值;}*/
- .class01,#id01{
- width:300px;
- height:100px;
- boarder:2px solid red;
- }
- style>
- head>
- <body>
- <div class="class01">韩顺平教育div>
- <p id="id01">hello,world~p>
- body>
- html>
行内样式>ID选择器>class选择器>元素选择器
CSS课后练习
CSS 测验




/*顺时针方向指定的*/

