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

Navicat for MySQL 11 Registration Code\Activation Code Summary

Recommended reading: Navicat12.1 series cracking ...

An article teaches you how to use Vue's watch listener

Table of contents Listener watch Format Set up th...

Control the vertical center of the text in the HTML text box through CSS

When the height attribute of Text is defined, the ...

WeChat applet realizes taking photos and selecting pictures from albums

This article shares the specific code for WeChat ...

Summary of Vue first screen performance optimization component knowledge points

Vue first screen performance optimization compone...

One question to understand multiple parameters of sort command in Linux

The sort command is very commonly used, but it al...

Three ways to implement text color gradient in CSS

In the process of web front-end development, UI d...

Example analysis of interval calculation of mysql date and time

This article uses an example to describe the inte...

Making a simple game engine with React Native

Table of contents Introduction Get started A brie...

How to configure Basic Auth login authentication in Nginx

Sometimes we build a file server through nginx, w...

Sample code for testing technology application based on Docker+Selenium Grid

Introduction to Selenium Grid Although some new f...

7 interview questions about JS this, how many can you answer correctly

Preface In JavaScript, this is the function calli...

A brief discussion on the use of React.FC and React.Component

Table of contents 1. React.FC<> 2. class xx...