HTML Basics Must-Read - Comprehensive Understanding of CSS Style Sheets

HTML Basics Must-Read - Comprehensive Understanding of CSS Style Sheets

CSS (Cascading Style Sheet) is used to beautify HTML web pages.

/*Comment area*/This is the comment syntax

1. Style Sheet

1. Classification of style sheets

1. Inline Style Sheets

Displayed jointly with HTML, the control is precise, but the reusability is poor and there is a lot of redundancy.

Example: <p style="font-size:14px;">Inline style sheet</p>

2. Embedded Style Sheets

As an independent area embedded in the web page, it must be written in the head tag.

<style type="text/css">

p //The format works on the p tag

{

style;

}

</style>

3. External Style Sheets

Create a new CSS file to store the style sheet. If you want to call a style sheet in an HTML file, you need to right-click in the HTML file → CSS Style Sheet → Attach Style Sheet. Generally, the link connection method is used.

Note: There is no need to write style tags in the css file

Some tags have default margins, which are usually removed when writing stylesheet code (other styles can also be set), as follows:

Note: The above picture shows that the margins and spacing are removed first.

(ii) Selector

1. Tag selector. Use tag names as selectors.

2.class selector. They all start with "." .

Note: The class selector can be superimposed with the tag selector to show different effects.

3.ID selector. Starts with “#” .

Note: The ID selector can be superimposed with the tag selector to show different effects.

<div id="style name">

4. Compound Selectors

(1) Use “,” to separate two items to indicate parallel order.

(2) Separated by spaces, indicating descendants.

(3) Filter “.”

2. Style attributes

1. Background and prospects

1. Background:

2. Foreground font:

2. Boundaries and borders

border (table border, style, etc.), margin (table spacing). padding (content and cell spacing).

3. Lists and blocks

width , height , ( top , bottom , left , right ) are only useful in the case of absolute coordinates.

The css stylesheet code shows:

CSS file code:

CSS CodeCopy content to clipboard
  1. @charset "utf-8" ;
  2. /* CSS Document */   
  3. * /*All tags work, margins and spacing are set to 0px*/   
  4. {
  5.      margin : 0px ;
  6.      padding : 0px ;}
  7. p,span /*Write a tag name directly to indicate that all p tags will execute this style*/   
  8. {
  9.      background-color : #F6C ;
  10.      color : #0F0 ;}
  11. p.sp
  12. {
  13.      background-color : #FF0 ;
  14.      color : red ;
  15.      font-size : 36px ;}
  16. .main /*Starting with ., use class to reference this style sheet*/   
  17. {
  18.      height : 50px ;
  19.      width : 300px ;
  20.      background-color : #0FF ;
  21.      font-size : 45px ;}
  22. .main p /*Indicates that if there is a p tag in the tag with class=main, this style will be executed*/   
  23. {
  24.      width : 400px ;
  25.      font-size : 36px ;}
  26. #main /*Starting with #, use the id selector to reference this style sheet*/   
  27. {
  28.      height : 60px ;
  29.      width : 500px ;
  30.      background-color : #60C ;
  31.      font-size : 36px ;}

HTML file code:

XML/HTML CodeCopy content to clipboard
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >   
  2. < html   xmlns = "http://www.w3.org/1999/xhtml" >   
  3. < head >   
  4. < meta   http-equiv = "Content-Type"   content = "text/html; charset=utf-8"   />   
  5. < title > Untitled Document </ title >   
  6. < style   type = "text/css" >   
  7.   
  8. </ style >   
  9. < link   href = "Untitled-1.css"   rel = "stylesheet"   type = "text/css"   />   
  10. </ head >   
  11.   
  12. < body >   
  13. < div   style = "background-color:#0F0" > 1234567 </ div >   
  14. < p > Spring is here. </ p >   
  15. < p > The flowers are blooming and the grass is green. </ p >   
  16. < p   class = "sp" > Geese, geese, geese, they sing with their necks bent toward the sky. </ p >   
  17. < span   class = "main" > Ploughing the field at noon < p > Sweat dripping down to the ground </ p > </ span >   
  18. < p   class = "main" > The sun sets over the mountains </ p >   
  19. < p   id = "main"   > Bright moonlight in front of the bed </ p >   
  20. < span > It may be frost on the ground </ span > < br   />   
  21. </ body >   
  22. </ html >   

The running effect shows:

The above article "Must-Read on HTML Basics - Comprehensive Understanding of CSS Style Sheets" is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

Original URL: http://www.cnblogs.com/H2921306656/archive/2016/07/10/5658628.html

<<:  9 code optimization tips to improve website usability that webmasters should pay attention to

>>:  An article to understand MySQL master-slave replication and read-write separation

Recommend

JavaScript to implement the function of changing avatar

This article shares the specific code of JavaScri...

Detailed explanation of Vue life cycle functions

Table of contents Lifecycle Functions Common life...

Practice of dynamically creating dialog according to file name in vue+el-element

Table of contents background accomplish 1. Encaps...

How to convert rows to columns in MySQL

MySQL row to column operation The so-called row-t...

Exploring the use of percentage values ​​in the background-position property

How background-position affects the display of ba...

JavaScript css3 to implement simple video barrage function

This article attempts to write a demo to simulate...

Analysis of Difficulties in Hot Standby of MySQL Database

I have previously introduced to you the configura...

IIS and APACHE implement HTTP redirection to HTTPS

IIS7 Download the HTTP Rewrite module from Micros...

Which scenarios in JavaScript cannot use arrow functions

Table of contents 1. Define object methods 2. Def...

SQL implements LeetCode (180. Continuous numbers)

[LeetCode] 180. Consecutive Numbers Write a SQL q...

Mysql online recovery of undo table space actual combat record

1 Mysql5.6 1.1 Related parameters MySQL 5.6 adds ...

Getting Started Tutorial for Beginners⑧: Easily Create an Article Site

In my last post I talked about how to make a web p...

js+canvas realizes code rain effect

This article shares the specific code of js+canva...