CSS Box Model
What is the CSS Box Model? The “Box Model” is a tool we use to lay out our web pages in a number of individual "boxes" or "containers".  When we plan our web page design, we must take into account not only the size of page content, but also the margins, borders, and padding involved. Before we start building a page, we can plan where everything will go by arranging these boxes on the screen.  Our goal is to create a balanced layout, with plenty of "white space" around the content.
The components of a box: Margin Border Content Padding
Introducing the <div> tag: The <div> tag is our basic building block when laying out a page design.  By defining the height and width of the <div>, we are &quot;reserving&quot; that amount of space on the screen for whatever content we wish to place there. The actual content will go inside the opening <div> and closing </div> tags.
Example <div>: By establishing the box dimensions, we can leave it there as a placeholder until we have our content ready.  In the meantime, the rest of the page can be built out with our other content. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border. </div> This is outside the box. This is a 300 by 300 pixel box with a 1 px border. This is outside the box.
Adding padding: By adding 10px of padding on all four sides of the content, we have effectively made our box 320px by 320px (321px by 321px with the border). <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px padding. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding. This is outside the box.
Adding margin: By adding 10px of margin on all four sides of the border, we have now made our box 341px by 341px overall. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; margin:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px Padding and 10px margin. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding and 10px margin. This is outside the box. The dotted line here shows where the margin is but it will not show on the actual page.
Calculating overall dimensions: When designing our page, we have to calculate how much size a <div> element will consume: Total element width = defined width + left padding + right padding + left border + right border + left margin + right margin. Total element height = defined height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
Pixels vs. Percent: The width property can be specified in pixels or in percent.  By using &quot;width:50%&quot;, we are telling the browser to make the width of the element exactly 50% of the space available. Using percent instead of pixels can make our page layout highly flexible.  For example, we can use the entire screen real estate, no matter what size screen or resolution our web visitor has.
A technique to center a <div>: Because we don't know what the screen resolution will be for our visitors, it can be challenging to get our pages to display attractively for all viewers. A useful technique is to set the right and left margins of a <div> to the value &quot;auto&quot;.  This tells the browser to maintain an equal distance on the right and left, effectively centering the <div> no matter how wide the available area is: .centerme {   margin:0 auto; } This same technique can be used on a <div> element that contains all your page content in order to center your page on the screen, no matter what the screen resolution of your web visitor.

More Related Content

PPT
Box Model
PDF
CSS3 Media Queries
PPTX
Css position
PPTX
Media queries A to Z
PDF
HTML CSS JS in Nut shell
PPT
Css Ppt
PPSX
CSS Box Model Presentation
PDF
Basics of JavaScript
Box Model
CSS3 Media Queries
Css position
Media queries A to Z
HTML CSS JS in Nut shell
Css Ppt
CSS Box Model Presentation
Basics of JavaScript

What's hot (20)

PPT
Java collections concept
PPTX
Css box-model
PDF
HTML & CSS Masterclass
PPTX
Introduction to flexbox
PDF
Introduction to HTML5
PPTX
Html5 semantics
PPTX
Introduction to HTML5 and CSS3 (revised)
PDF
Web 2 | CSS - Cascading Style Sheets
PDF
JavaScript Programming
PDF
Bootstrap
PDF
HTML and CSS crash course!
PPTX
PPTX
Complete Lecture on Css presentation
PPT
jQuery Ajax
PDF
CSS Day: CSS Grid Layout
PPTX
Css floats
PPTX
Html5 and-css3-overview
PDF
CSS3, Media Queries, and Responsive Design
PDF
Java collections concept
Css box-model
HTML & CSS Masterclass
Introduction to flexbox
Introduction to HTML5
Html5 semantics
Introduction to HTML5 and CSS3 (revised)
Web 2 | CSS - Cascading Style Sheets
JavaScript Programming
Bootstrap
HTML and CSS crash course!
Complete Lecture on Css presentation
jQuery Ajax
CSS Day: CSS Grid Layout
Css floats
Html5 and-css3-overview
CSS3, Media Queries, and Responsive Design
Ad

Viewers also liked (20)

PDF
Css box model
PPTX
The CSS Box Model
PDF
CSS Box Model
PDF
CSS Layouting #3 : Box Model
PPT
CSS, CSS Selectors, CSS Box Model
PPTX
The Box Model [CSS Introduction]
PDF
CSS Box Model and Dimensions
PPTX
CSS Layout Techniques
PPTX
Google's Principle's of Mobile Website Design
PPTX
Introduction about wireframing and responsive webdesign
KEY
Lecture3
PDF
Next Steps in Responsive Design
KEY
Interactive Graphics using Javascript, HTML5 and CSS3
PPT
Webdesign New
PPTX
10 Design and Layout Principles Guaranteed to Improve Your Website V2
PDF
CSS Dasar #6 : Background
PPT
Css page layout
PPTX
Introduction to computers
PPT
Page Layout 2010
PPTX
Lesson One Fourth Quarter Fourth Year High School CSS Modern Layout and Style
Css box model
The CSS Box Model
CSS Box Model
CSS Layouting #3 : Box Model
CSS, CSS Selectors, CSS Box Model
The Box Model [CSS Introduction]
CSS Box Model and Dimensions
CSS Layout Techniques
Google's Principle's of Mobile Website Design
Introduction about wireframing and responsive webdesign
Lecture3
Next Steps in Responsive Design
Interactive Graphics using Javascript, HTML5 and CSS3
Webdesign New
10 Design and Layout Principles Guaranteed to Improve Your Website V2
CSS Dasar #6 : Background
Css page layout
Introduction to computers
Page Layout 2010
Lesson One Fourth Quarter Fourth Year High School CSS Modern Layout and Style
Ad

Similar to 5.1 css box model (20)

PDF
11--CSS-Box-Model.pdf for second college
PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
PPT
Advance Css
PPT
Advance Css 1194323118268797 5
PPT
What I brought back from Austin
ODP
Creating Web Sites with HTML and CSS
PDF
Margin vs Padding.pdf
PPT
CSS Basics
ODP
Cascading Style Sheets - Part 02
PPT
Basics Of Css And Some Common Mistakes
PDF
Bhanu pratap
PPTX
Lect-4-Responsive-Web-06032024-082044am.pptx
PPT
CSS For Online Journalism
PDF
Flex Web Development.pdf
PPTX
CSS3 notes
PDF
Pemrograman Web 2 - CSS
PPTX
Visualforce css developer guide(by forcetree.com)
ODP
Srijan presentation on CSS
PPT
CSS 101
11--CSS-Box-Model.pdf for second college
Pixel to Percentage conversion Convert left and right padding of a div to per...
Advance Css
Advance Css 1194323118268797 5
What I brought back from Austin
Creating Web Sites with HTML and CSS
Margin vs Padding.pdf
CSS Basics
Cascading Style Sheets - Part 02
Basics Of Css And Some Common Mistakes
Bhanu pratap
Lect-4-Responsive-Web-06032024-082044am.pptx
CSS For Online Journalism
Flex Web Development.pdf
CSS3 notes
Pemrograman Web 2 - CSS
Visualforce css developer guide(by forcetree.com)
Srijan presentation on CSS
CSS 101

More from Bulldogs83 (19)

PPT
7.2 external style sheets
PPT
7.1 xhtml validation
PPT
6.2 css link styling
PPT
6.1 special characters
PPT
5.2 nesting and floating elements
PPT
4.3 table styling
PPT
4.2 css classes
PPT
4.1 advanced tables
PPT
3.2 introduction to css
PPT
3.1 xhtml tables
PPT
3.2 introduction to css
PPT
2.1 adding images
PPT
1.4 adding comments copy (2)
PPT
1.4 adding comments copy (2)
PPT
1.3 creating links
PPT
1.3 creating links
PPT
1.2 elements and attributes copy (3)
PPT
1.2 elements and attributes copy (3)
PPT
1.1 xhtml basics
7.2 external style sheets
7.1 xhtml validation
6.2 css link styling
6.1 special characters
5.2 nesting and floating elements
4.3 table styling
4.2 css classes
4.1 advanced tables
3.2 introduction to css
3.1 xhtml tables
3.2 introduction to css
2.1 adding images
1.4 adding comments copy (2)
1.4 adding comments copy (2)
1.3 creating links
1.3 creating links
1.2 elements and attributes copy (3)
1.2 elements and attributes copy (3)
1.1 xhtml basics

Recently uploaded (20)

PDF
HSE and their team are going through the hazards of the issues with learning ...
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
macro complete discussion with given activities
PPTX
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PDF
Developing speaking skill_learning_mater.pdf
PPTX
CHF refers to the condition wherein heart unable to pump a sufficient amount ...
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PDF
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
PDF
IS1343_2012...........................pdf
PPTX
INTRODUCTION TO PHILOSOPHY FULL SEM - COMPLETE.pptxINTRODUCTION TO PHILOSOPHY...
PDF
FYJC - Chemistry textbook - standard 11.
PPTX
Juvenile delinquency-Crim Research day 3x
PPTX
Environmental Sciences and Sustainability Chapter 2
PDF
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
PPTX
Entrepreneurship Management and Finance - Module 1 - PPT
PPTX
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
PDF
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
DOCX
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
PDF
New_Round_Up_6_SB.pdf download for free, easy to learn
HSE and their team are going through the hazards of the issues with learning ...
hsl powerpoint resource goyloveh feb 07.ppt
macro complete discussion with given activities
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
MMW-CHAPTER-1-final.pptx major Elementary Education
Developing speaking skill_learning_mater.pdf
CHF refers to the condition wherein heart unable to pump a sufficient amount ...
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
IS1343_2012...........................pdf
INTRODUCTION TO PHILOSOPHY FULL SEM - COMPLETE.pptxINTRODUCTION TO PHILOSOPHY...
FYJC - Chemistry textbook - standard 11.
Juvenile delinquency-Crim Research day 3x
Environmental Sciences and Sustainability Chapter 2
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
Entrepreneurship Management and Finance - Module 1 - PPT
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
New_Round_Up_6_SB.pdf download for free, easy to learn

5.1 css box model

  • 2. What is the CSS Box Model? The “Box Model” is a tool we use to lay out our web pages in a number of individual &quot;boxes&quot; or &quot;containers&quot;. When we plan our web page design, we must take into account not only the size of page content, but also the margins, borders, and padding involved. Before we start building a page, we can plan where everything will go by arranging these boxes on the screen. Our goal is to create a balanced layout, with plenty of &quot;white space&quot; around the content.
  • 3. The components of a box: Margin Border Content Padding
  • 4. Introducing the <div> tag: The <div> tag is our basic building block when laying out a page design. By defining the height and width of the <div>, we are &quot;reserving&quot; that amount of space on the screen for whatever content we wish to place there. The actual content will go inside the opening <div> and closing </div> tags.
  • 5. Example <div>: By establishing the box dimensions, we can leave it there as a placeholder until we have our content ready. In the meantime, the rest of the page can be built out with our other content. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border. </div> This is outside the box. This is a 300 by 300 pixel box with a 1 px border. This is outside the box.
  • 6. Adding padding: By adding 10px of padding on all four sides of the content, we have effectively made our box 320px by 320px (321px by 321px with the border). <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px padding. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding. This is outside the box.
  • 7. Adding margin: By adding 10px of margin on all four sides of the border, we have now made our box 341px by 341px overall. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; margin:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px Padding and 10px margin. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding and 10px margin. This is outside the box. The dotted line here shows where the margin is but it will not show on the actual page.
  • 8. Calculating overall dimensions: When designing our page, we have to calculate how much size a <div> element will consume: Total element width = defined width + left padding + right padding + left border + right border + left margin + right margin. Total element height = defined height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
  • 9. Pixels vs. Percent: The width property can be specified in pixels or in percent. By using &quot;width:50%&quot;, we are telling the browser to make the width of the element exactly 50% of the space available. Using percent instead of pixels can make our page layout highly flexible. For example, we can use the entire screen real estate, no matter what size screen or resolution our web visitor has.
  • 10. A technique to center a <div>: Because we don't know what the screen resolution will be for our visitors, it can be challenging to get our pages to display attractively for all viewers. A useful technique is to set the right and left margins of a <div> to the value &quot;auto&quot;. This tells the browser to maintain an equal distance on the right and left, effectively centering the <div> no matter how wide the available area is: .centerme { margin:0 auto; } This same technique can be used on a <div> element that contains all your page content in order to center your page on the screen, no matter what the screen resolution of your web visitor.