Home Web Front-end HTML Tutorial Detailed explanation of html box model

Detailed explanation of html box model

Mar 09, 2018 am 10:40 AM
html Model Detailed explanation

This time I will bring you a detailed explanation of the html box model. What are the precautions when using the html box model. The following is a practical case, let's take a look.

1.1. The size of the content area of ​​the box—content width and content height—depends on several factors:

--Whether the element that generates the box has 'width' or 'height' set Attributes.
--Whether the box contains text and other boxes.
--Whether the box is a table, etc.

1.2. The background color of the box

--The background style of the padding and border areas is specified by the 'background' attribute of the element that generates (the box) . The margin background is always transparent

2. Margin attributes: 'margin-top', 'margin-right', 'margin-bottom' ', 'margin-left' and 'margin'

##2.1. The margin attribute specifies the width of the box's margin area

--'margin'简写属性一次性设置四周的外边距,而其它外边距属性只设置它们各侧的。这些属性适用于所有元素,但非替换的行内元素上的垂直margin将不会产生任何效果
Copy after login

2.2. < ;margin-width> value type, which can take one of the following values:


--<length>
指定一个固定宽度
--<percentage>
百分比根据生成盒的包含块的width来计算。注意,这一点对于&#39;margin-top&#39;和&#39;margin-bottom&#39;也适用。如果包含块的宽度取决于该元素,那么产生的布局在CSS 2.1是未定义的
--auto
--margin属性允许负值,但可能存在具体实现限制
Copy after login

2.3. 'margin-top', 'margin-bottom'

&#39;margin-top&#39;, &#39;margin-bottom&#39;
Value:      <margin-width> | inherit
Initial:    0
Applies to: 除display类型为table系列中除了table-caption,table和inline-table以外的所有元素(译注:也就是说,table系列display值中,margin-只适用于table-caption, table, inline-table,其余的都不适用,但margin-对非table系列都适用)
Inherited:      no
Percentages:    参照包含块的宽度
Media:      visual
Computed value:     指定的百分比或者绝对长度
Copy after login

These two attributes are correct Non-replaced inline elements are invalid


2.4. 'margin-right', 'margin-left'

&#39;margin-right&#39;, &#39;margin-left&#39;
Value:      <margin-width> | inherit
Initial:    0
Applies to:     除display类型为table系列中除了table-caption,table和inline-table以外的所有元素(译注:也就是说,table系列display值中,margin-只适用于table-caption, table, inline-table,其余的都不适用,但margin-对非table系列都适用)
Inherited:      no
Percentages:    参照包含块的宽度
Media:      visual
Computed value:     指定的百分比或者绝对长度
Copy after login

2.5. 'margin'

&#39;margin&#39;
Value:      <margin-width>{1,4} | inherit
Initial:    见单独的各个属性
Applies to:     除display类型为table系列中除了table-caption,table和inline-table以外的所有元素(译注:也就是说,table系列display值中,margin-只适用于table-caption, table, inline-table,其余的都不适用,但margin-对非table系列都适用)
Inherited:      no
Percentages:    参照包含块的宽度
Media:      visual
Computed value:     见单独的各个属性
Copy after login

3. Merge Margins

Adjacent vertical margins will be merged, except:

----The margins of the root element box will not be merged

----If one has a clearance (clearance Translation Note: refers to the gap formed by the clear attribute causing the position of the element to move). The upper margin of the element is adjacent to the lower margin. Its margin will be merged with the adjacent margin of the immediately adjacent sibling (element), but the merge It will no longer be merged with the lower margin of the parent block

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Related reading:

How to quickly create html header code in sublime

What are the length units in css

CSS(Cascading Style Sheets) collection

The above is the detailed content of Detailed explanation of html box model. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

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

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

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.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

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

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

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

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

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

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

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

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

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

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

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

See all articles