" tag in the "" part of the HTML document to include CSS Rules; 3. External style sheet, write CSS rules in a separate ".css" file, and then in the HTML document and so on."> What are the methods of setting HTML space_How to set HTML space-Common Problem-php.cn
Home> Common Problem> body text

HTML space setting method

百草
Release: 2023-11-16 10:05:57
Original
776 people have browsed it

HTML space setting methods include: 1. Inline style; 2. Internal style sheet; 3. External style sheet; 4. Use margin and padding attributes. Detailed introduction: 1. Inline style, use the style attribute directly in the HTML element to set the CSS style; 2. 2. Internal style sheet, use the "  

    
我是一个 div
  
Copy after login

3. External style sheet: Write the CSS rules in a separate .css file, and then use the tag to reference this file in the HTML document. For example:

    
    
我是一个 div
  
Copy after login

In the styles.css file:

div {padding: 20px;}
Copy after login

Among the above three methods, the external style sheet method is the most recommended, because this can achieve the separation of style and content, making the website Maintenance and style modifications are more convenient. At the same time, external style sheets can also be shared by multiple pages, which can improve the performance of the website.

4. Use the margin and padding attributes: These two attributes can set the outer margin and inner margin of the element respectively. For example, margin: 10px; sets the element's outer margin to 10 pixels, and padding: 20px; sets the element's inner margin to 20 pixels. Both properties can accept four values ​​(top, right, bottom, left), two values ​​(top, bottom, left), or one value (all). For example:

div {margin: 10px; /* 设置外边距为10像素 */  padding: 20px; /* 设置内边距为20像素 */  }
Copy after login

or:

div {margin: 10px 15px; /* 设置上下外边距为10像素,左右外边距为15像素 */  padding: 20px 25px; /* 设置上下内边距为20像素,左右内边距为25像素 */  }
Copy after login

or:

div {margin: 10px 15px 20px 25px; /* 设置上外边距为10像素,右外边距为15像素,下外边距为20像素,左外边距为25像素 */  padding: 20px 25px; /* 设置上下内边距为20像素,左右内边距为25像素 */  }
Copy after login

Note that the values ​​of margin and padding can be in units such as pixels (px), percentage (%), em, etc. It can also be a relative unit (such as em). In addition, among the four values ​​of margin, if the first two values ​​​​are positive numbers, the first two values ​​​​represent the top and bottom margins; if the last two values ​​​​are positive numbers, the last two values ​​​​represent the left and right margins. Similarly, among the four values ​​​​of padding, if the first two values ​​​​are positive numbers, the first two values ​​​​represent the top and bottom padding; if the last two values ​​​​are positive numbers, the last two values ​​​​represent the left and right padding. .

The above is the detailed content of HTML space setting method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!