current position:Home>How to define and use HTML box model

How to define and use HTML box model

2022-04-29 17:25:32Billion cloud speed

html How to define and use the box model

Today I'd like to share with you html How the box model defines the relevant knowledge points used , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .

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

-- Whether the element generating the box is set to 'width' or 'height' attribute .
-- Whether the box contains text and other boxes .
-- Whether the box is a form, etc .

1.2. The background color of the box

-- The background style of the inner margin and border area is generated by ( Of the box ) Elemental 'background' Property to specify . The outer margin background is always transparent

2. Outer margin property : 'margin-top','margin-right','margin-bottom','margin-left' and 'margin'

2.1. The outer margin attribute specifies the width of the outer margin area of the box

--'margin' The shorthand property sets the outer margin around at one time , The other outer margin attributes only set the margin on each side of them . These attributes apply to all elements , But vertical on non substituted inline elements margin There will be no effect 

2.2. <margin-width> Value type , You can take one of the following values :

--<length> Specify a fixed width --<percentage> The percentage is based on the number of blocks contained in the generated box width To calculate . Be careful , This is for 'margin-top' and 'margin-bottom' Also applicable . If included, the width of the block depends on the element , So the resulting layout is CSS 2.1 It's undefined --auto--margin Property allows negative values , However, there may be specific implementation limitations 

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

'margin-top', 'margin-bottom'Value:      <margin-width> | inheritInitial:    0Applies to:  except display The type is table Except for table-caption,table and inline-table All elements other than ( Translation notes : in other words ,table series display In the value ,margin- Only applicable to table-caption, table, inline-table, The rest don't apply , but margin- Right table All series are applicable )Inherited:      noPercentages:     The reference contains the width of the block Media:      visualComputed value:      Specified percentage or absolute length 

These two attributes are not valid for non replaceable inline elements

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

'margin-right', 'margin-left'Value:      <margin-width> | inheritInitial:    0Applies to:      except display The type is table Except for table-caption,table and inline-table All elements other than ( Translation notes : in other words ,table series display In the value ,margin- Only applicable to table-caption, table, inline-table, The rest don't apply , but margin- Right table All series are applicable )Inherited:      noPercentages:     The reference contains the width of the block Media:      visualComputed value:      Specified percentage or absolute length 

2.5. 'margin'

'margin'Value:      <margin-width>{1,4} | inheritInitial:     See individual attributes Applies to:      except display The type is table Except for table-caption,table and inline-table All elements other than ( Translation notes : in other words ,table series display In the value ,margin- Only applicable to table-caption, table, inline-table, The rest don't apply , but margin- Right table All series are applicable )Inherited:      noPercentages:     The reference contains the width of the block Media:      visualComputed value:      See individual attributes 

3. Merge outer margins

Adjacent vertical margins merge , except :

---- Of the root element box margin Do not merge
---- If one has a gap (clearance Translation notes : Refer to clear Attribute causes the position of the element to move ) The upper outer margin of the element is adjacent to the lower outer margin , Its outer margin will be close to the brothers ( Elements ) Merge adjacent outer margins of , But after merging, it will not merge with the lower outer margin of the parent block

That's all “html How to define and use the box model ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .

copyright notice
author[Billion cloud speed],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291539468062.html

Random recommended