Technical point 2: CSS

Guo Shao 2020-11-08 19:27:07
technical point css


CSS technology

One 、CSS Technology is introduced

CSS yes 「 Cascading style forms 」. Is used for ( enhance ) A markup language that controls web page styles and allows the separation of style information from web content .

Two 、CSS Rule of grammar

 

  Selectors : The selector determines what HTML Elements need to use this style ;

attribute : It's the name of the style that needs to be changed , Attribute names and values use ":" Division , At the end of a property declaration, you must add ";"

Multiple attributes : Another line , Then write .

give an example :

p{
color:red;
font-size:20px;
}

notes : Generally, each line only describes one attribute

 

3、 ... and 、CSS Notes

/* The comment */

 

Four 、CSS and HTML The combination of

1. The first one is

demand 1: Define two div、span label , Modify each one separately div The style of the label is : Frame 1 Pixel , Solid line , Red .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
</head>
<body>
<!-- demand 1: Define two div、span label , Modify each one separately div Style of label
by : Frame 1 Pixel , Solid line , Red .-->
<div style="border: 1px solid red;">div1</div>
<div style="border: 1px solid red;">div2</div>
<span>span1</span>
<span>span2</span>
</body>
</html>

The effect is as follows :

 

  The disadvantages of the above methods ?

1. If there are too many labels , There are more styles , The amount of code is huge ;

2. Very bad readability ;

3.CSS Styles are not reused ;

 

2. The second kind

demand 1: Define two div、span label , Modify each one separately div The style of the label is : Frame 1 Pixel , Solid line , Red .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<style type="text/css">
/* demand 1: Define two div、span label , Modify each one separately div Style of label */
/* by : Frame 1 Pixel , Solid line , Red .*/
div{
border: 1px solid red;
}
</style>
</head>
<body>
<div>div1</div>
<div>div2</div>
<span>span1</span>
<span>span2</span>
</body>
</html>

The effect is as follows :

 

  The disadvantages of the above methods ?

1. Code can only be reused within the same page , It can't be reused in multiple pages css Code .
2. It's not convenient to maintain , There will be thousands of pages in a real project , Go to each page to modify . It's too much work .

 

3. The third kind of

Create a hello.css file , The contents are as follows :

div {
border: 1px solid red;
}
span{
border: 1px dashed blue;
}

stay HTML Page head Use in Tags link Label introduction :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<link rel="stylesheet" href="hello.css" type="text/css">
</head>
<body>
<div>div1</div>
<div>div2</div>
<span>span1</span>
<span>span2</span>
</body>
</html>

The effect is as follows :

 

 

5、 ... and 、CSS Selectors

1. Tag name selector

 Format :
Tag name {
Property name : value ;
}

demand 1: In all div Change the font color on the label to blue , font size 30 Pixel . Border is 1 Pixel yellow solid line . And modify all span The font color of the label is yellow , font size 20 Pixel . Border is 5 Pixel blue dotted line .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<style type="text/css">
div{
color: blue;
font-size: 30px;
border: 1px yellow solid;
}
span{
color: yellow;
font-size: 20px;
border: 5px blue dashed;
}
</style>
</head>
<body>
<!-- demand 1: In all div Change the font color on the label to blue , font size 30 Pixel . Border is 1 Pixel yellow solid line .-->
<!-- And modify all span The font color of the label is yellow , font size 20 Pixel . Border is 5 Pixel blue dotted line .-->
<div>div1</div>
<div>div2</div>
<span>span1</span>
<span>span2</span>
</body>
</html>

The effect is as follows :

 

 

2.id Selectors

 Format :
#id Property value {
Property name : value ;
}

demand 1: Define two div label . first div Tag definition id by id001 , And then according to id Attribute definitions css Style change font color to blue , font size 30 Pixel . Border is 1 Pixel yellow solid line . the second div Tag definition id by id002 , And then according to id Attribute definitions css style Change the font color to red , font size 20 Pixel . Border is 5 Pixel blue dot line .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<style type="text/css">
#id001{
color: blue;
font-size: 30px;
border: 1px yellow solid;
}
#id002{
color: red;
font-size: 20px;
border: 5px blue dotted;
}
</style>
</head>
<body>
<!-- demand 1: Define two div label .
first div Tag definition id by id001 , And then according to id Attribute definitions css Style change font color to blue ,
font size 30 Pixel . Border is 1 Pixel yellow solid line .
the second div Tag definition id by id002 , And then according to id Attribute definitions css style Change the font color to red ,
font size 20 Pixel . Border is 5 Pixel blue dot line .-->
<div id="id001">div1</div>
<div id="id002">div2</div>
</body>
</html>

The effect is as follows :

 

 

3. Class selectors (class Selectors )

 Format :
.class Property value {
attribute : value ;
}

demand 1: modify class The property value is class01 Of span or div label , The font color is blue , font size 30 Pixel . Border is 1 Pixel yellow solid line . demand 2: modify class The property value is class02 Of div label , The font color is gray , font size 26 Pixel . Border is 1 Pixel red solid line .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<style type="text/css">
.class01{
color: blue;
font-size: 30px;
border: 1px yellow solid;
}
.class02{
color: gray;
font-size: 26px;
border: 1px red solid;
}
</style>
</head>
<body>
<!-- demand 1: modify class The property value is class01 Of span or div label , The font color is blue ,
font size 30 Pixel . Border is 1 Pixel yellow solid line .
demand 2: modify class The property value is class02 Of div label , The font color is gray ,
font size 26 Pixel . Border is 1 Pixel red solid line .-->
<div class="class01">div label 1</div>
<div class="class02">div label 2</div>
<span class="class01">span label 1</span>
<span class="class02">span label 2</span>
</body>
</html>

The effect is as follows :

 

 

4. Combination selector

 Format :
Selectors 1, Selectors 2...{
attribute : value ;
}

demand 1: modify class="class01" Of div label and id="id01" be-all span label , The font color is blue , font size 20 Pixel . Border is 1 Pixel yellow solid line .

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS and HTML combination </title>
<style type="text/css">
.class01,#id01{
color: blue;
font-size: 20px;
border: 1px yellow solid;
}
</style>
</head>
<body>
<!-- demand 1: modify class="class01" Of div label and id="id01" be-all span label , The font color is blue ,
font size 20 Pixel . Border is 1 Pixel yellow solid line .-->
<div class="class01">div label 1</div>
<div class="class02">div label 2</div>
<span id="id01">span label 1</span>
<span class="class02">span label 2</span>
</body>
</html>

The effect is as follows :

 

 

6、 ... and 、 Common styles

1. The font color

color:red;
Colors can be written with color names such as :black, blue, red, green etc.
Color can also be written rgb Values and hexadecimal represent values : Such as rgb(255,0,0),#00F6DE, If you write a hexadecimal value, you must add #.

2. Width width

width: 19px;

Width can be written in pixels :19px;

You can also write a percentage value :20%;

3. Height height

height: 20px;

Height can be written in pixels :19px;

You can also write a percentage value :20%;

4. The background color

background-color:#0F2D4C

5. Font style

The font color :color

font size :font-size

6. Frame

border:1px solid red;

7.div In the middle

margin-left: auto;

margin-right: auto;

8. Center text

text-align: center;

9. Underline hyperlinks

text-decoration: none;

10. Fine lines in the table

table{
border: 1px solid black;
border-collapse: collapse;
}
th,td{
border: 1px solid black;
}

11. List removal embellishment

ul{
list-style: none;
}

Sample code :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Common styles </title>
<style type="text/css">
div{
color: red;
border: 1px solid yellow;
width: 300px;
height: 300px;
background-color: green;
font-size: 30px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
table{
border: 1px solid black;
border-collapse: collapse;
}
td{
border: 1px solid black;
}
a{
text-decoration: none;
}
ul{
list-style: none;
}
</style>
</head>
<body>
<div> I am a div label </div>
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
</tr>
</table>
<a href="http://www.baidu.com"> use Baidu Search </a>
<ul>
<li>1111111</li>
<li>1111111</li>
<li>1111111</li>
<li>1111111</li>
</ul>
</body>
</html>

The effect is as follows :

 

版权声明
本文为[Guo Shao]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple