<p style="color:red">这里文字是红色。</p>
<style type="text/css">span{color:red;}</style>
Summary of several key points in html learning
Key summary about html
Block elements, inline elements, inline block elements
HTML can classify elements into There are three types of inline elements, block elements and inline block elements
Using the display attribute, the three can be converted arbitrarily
Block elements automatically Line break
Conversion method
(1)display:inline;Convert to inline element
(2)display:block;Convert to block element
(3)display:inline-block;Convert to inline block elementCompare
1.Inline element
The most commonly used inline element is span, and the others are only used under specific functions, modifying the font <b>
and <i>
tags, and There are two tags, <sub>
and <sup>
, which can directly create a square effect without the help of similar movement attributes, which is very practical.
Characteristics of inline elements: (1) Setting width and height is invalid
(2) Setting margin is only effective in left and right directions, not up and down; padding setting is effective in both up, down, left and right directions, which will expand the space
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>行内元素</title> <style type="text/css"> span { width: 120px; height: 120px; margin: 1000px 20px; padding: 50px 40px; background: lightblue; } </style> </head> <body> <sspan>不会自动换行</span> <span>行内元素</span> </body> </html>
2. Block element
The representative block element is p, others such as p, nav, aside, header, Footer, section, article, ul-li, address, etc. can all be implemented using p. However, in order to facilitate programmers to interpret the code, specific semantic tags are generally used to make the code more readable and easy to check for errors.
Characteristics of block elements: (1) Able to recognize width and height
(2) The top, bottom, left and right margins and padding are all valid for it
(3) Can automatically wrap lines
graduate down through the arrangement by default
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>块状元素</title> <style type="text/css"> p { width: 120px; height: 120px; margin: 50px 50px; padding: 50px 40px; background: lightblue; } </style> </head> <body> <i>自动换行</i> <p>块状元素</p> <p>块状元素</p> </body> </html>
3. Inline block elements
Comprehensive inline block elements It combines the characteristics of inline elements and block elements, but each has its own trade-offs. Therefore, inline block elements are used more often due to their characteristics in daily use.
Characteristics of inline block elements: (1) No automatic line wrapping
#
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>行内块状元素</title> <style type="text/css"> p { display: inline-block; width: 100px; height: 50px; background: lightblue; } </style> </head> <body> <p>行内块状元素</p> <p>行内块状元素</p> </body> </html>
- Relative path: refers to the path relationship with other files (or folders) caused by the path where this file is located
- Each one. Jump one level outward.
- Three ways to write styles
<p style="color:red">这里文字是红色。</p>
Copy after login
2. Embedded style: Embedded css style means that you can write css style code between tags <p style="color:red">这里文字是红色。</p>
<style type="text/css">span{color:red;}</style>
Copy after login
3. External style sheet: External css style (also called external style) is to write the css code in a separate external file. This css style file has the extension ".css" <style type="text/css">span{color:red;}</style>
<link href="style.css" rel="stylesheet" type="text/css" />
Copy after loginNote:
css style file name must comply with the naming rules, such as main.css<link href="style.css" rel="stylesheet" type="text/css" />
- rel=”stylesheet” type=”text/css” is a fixed writing method that cannot be modified
- css files can also be introduced using import in
- , but this method cannot be operated with js
Absolute positioning, relative positioning and fixed positioning
2. You can use the position attribute to place an element anywhere on the web page.
Optional values:
- static: Default value, the element does not have positioning enabled
– relative: Turn on relative positioning
– absolute: Turn on absolute positioning
- fixed: Turn on fixed positioning
3. Relative positioning
——-Relative positioning will not change the original characteristics of the element. Block element or block element, inline or inline
- Relative positioning will raise the level of the element so that the element can cover elements in the text flow.
4. Absolute positioning
①Absolute positioning means that the element is positioned relative to the html element or its nearest ancestor positioning element.
②When the position attribute is set to absolute, the absolute positioning of the element is turned on.
③When absolute positioning is turned on, you can use the four attributes top, right, bottom, and left to position the element.
④Characteristics of absolute positioning:
——Absolute positioning will completely separate the element from the text flow.
——-The width of an absolutely positioned block element will be stretched by its content.
——Absolute positioning will turn inline elements into block elements.
——-Absolute positioning is relative to the nearest ancestor element that has positioning turned on. If all ancestors do not have positioning turned on, they will be positioned relative to the browser window.
——Generally, when using absolute positioning, a relative positioning will be specified for its parent element to ensure that the element can be positioned relative to the parent element.
——-Absolute positioning will increase the level of the element.
5. Fixed positioning
①Fixed positioning elements will be locked at a certain position on the screen. When the visitor scrolls the web page, the fixed elements will remain stationary on the screen
②When the position attribute is set to fixed, the fixed positioning of the element is turned on.
③When fixed positioning is turned on, the four attributes of top, right, bottom, and left can be used to position the element.
④ Fixed positioning is also a kind of absolute positioning. Other characteristics of fixed positioning are similar to absolute positioning.
Difference:
(1) Fixed positioning is always relative to the browser positioning.
(2) will be fixed at a certain position in the browser window and will not scroll with the scroll bar.
(3)IE6 does not support fixed positioning.
The above is the detailed content of Summary of several key points in html learning. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
