Home  >  Article  >  Web Front-end  >  Understanding the box model

Understanding the box model

巴扎黑
巴扎黑Original
2017-06-23 14:53:031925browse

There are two types of box models: W3C and IE box models

The box model includes margin, border, padding, and content

W3C element width = content width

IE's element width = content+padding+border

I personally think that the box model defined by W3C is more reasonable than the box model defined by IE. The

element The width should include border and padding. This is the same as the box in our real life.

W3C also recognized its own problem, so it added a new style box in CSS3- sizing,

contains two attributes content-box and border-box.

content-box: width=content+padding+border

border-box: width=width (width specified by style)

1. For row-level elements, margin-top and margin-bottom are invalid for upper and lower elements, and margin-left and margin-right are valid

2. For adjacent block-level elements, margin-bottom and margin-top value methods

1) All are positive numbers: take the maximum value Distance=Math.max(margin-botton,margin-top)

2) All are negative numbers: take the minimum value Distance=Math.min( margin-botton,margin-top)

3) The top is a positive number and the bottom is a negative number or the top is a negative number and the bottom is a positive number: Addition of positive and negative distances=margin-botton+margin-top

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

Statement:
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