SlideShare uma empresa Scribd logo
1 de 36
The Box Model Colin Gourlay & Kevin Vanderbeken
Today: The Box Model Container Elements Other Text Features
introduction
an aside on tables...
the CSS layout model a.k.a. the box model
margin
outline
border
padding
content HEGHT WIDTH
more detail + code examples
margin
margin-top: 3px; margin-right: 5px; margin-bottom: 7px; margin-left: 2px; ...or... margin: 3px 5px 7px 2px;
outline
none dotted dashed solid double groove ridge inset outset outline-color: #999999; outline-style: dotted; outline-width: 5px; ...or... outline: #999999 dotted 5px;
width & height
width: 200px; height: 120px;
border
none dotted dashed solid double groove ridge inset outset border-color: #00FF00; border-style: dotted; border-width: 5px; ...or... border: 5px solid #00FF00; ...but wait, there’s more!...
border-top-width: 2px; border-right-width: 5px; border-bottom-width: 2px; border-left-width: 5px; ...and... border-top: 2px solid #00FF00;
padding
padding-top: 3px; padding-right: 5px; padding-bottom: 7px; padding-left: 2px; ...or... padding: 3px 5px 7px 2px;
recap
margin
outline
border
padding
content HEGHT WIDTH
text features worth mentioning
line height
line-height: 24px;
text alignment
text-align: left; text-align: right; text-align: center; text-align: justify;
next week...
More on The Box ModelTM Different boxes: block & inline Box interaction: floats & positioning

Mais conteúdo relacionado

Semelhante a Box Model Guide to Margins, Padding, Borders, and More

Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSSColin Loretz
 
Harendra Singh,BCA Third Year
Harendra Singh,BCA Third YearHarendra Singh,BCA Third Year
Harendra Singh,BCA Third Yeardezyneecole
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 
CSSO – compress CSS (english version)
CSSO – compress CSS (english version)CSSO – compress CSS (english version)
CSSO – compress CSS (english version)Roman Dvornov
 
SASS In The Real World
SASS In The Real WorldSASS In The Real World
SASS In The Real Worldfesuffolk
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & CompassRob Davarnia
 
HTML5 and CSS3 Refresher
HTML5 and CSS3 RefresherHTML5 and CSS3 Refresher
HTML5 and CSS3 RefresherIvano Malavolta
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)elliando dias
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 

Semelhante a Box Model Guide to Margins, Padding, Borders, and More (20)

Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSS
 
CSS Box Model
CSS Box ModelCSS Box Model
CSS Box Model
 
Lab#7 CSS Box Model
Lab#7 CSS Box ModelLab#7 CSS Box Model
Lab#7 CSS Box Model
 
CSS and Layout
CSS and LayoutCSS and Layout
CSS and Layout
 
Harendra Singh,BCA Third Year
Harendra Singh,BCA Third YearHarendra Singh,BCA Third Year
Harendra Singh,BCA Third Year
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
UI 101
UI 101UI 101
UI 101
 
Lecture 3: HTML & CSS
Lecture 3: HTML & CSSLecture 3: HTML & CSS
Lecture 3: HTML & CSS
 
The Future of CSS
The Future of CSSThe Future of CSS
The Future of CSS
 
CSSO – compress CSS (english version)
CSSO – compress CSS (english version)CSSO – compress CSS (english version)
CSSO – compress CSS (english version)
 
SASS In The Real World
SASS In The Real WorldSASS In The Real World
SASS In The Real World
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
 
Gmail tutorials
Gmail tutorialsGmail tutorials
Gmail tutorials
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
HTML5 and CSS3 Refresher
HTML5 and CSS3 RefresherHTML5 and CSS3 Refresher
HTML5 and CSS3 Refresher
 
Css for nondesigners
Css for nondesignersCss for nondesigners
Css for nondesigners
 
Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)Compass And Sass(Tim Riley)
Compass And Sass(Tim Riley)
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 

Mais de apnwebdev

1 05-css for-text_and_backgrounds
1 05-css for-text_and_backgrounds1 05-css for-text_and_backgrounds
1 05-css for-text_and_backgroundsapnwebdev
 
1 04-html elements
1 04-html elements1 04-html elements
1 04-html elementsapnwebdev
 
1-07: The Box Model
1-07: The Box Model1-07: The Box Model
1-07: The Box Modelapnwebdev
 
1-06: More HTML Elements
1-06: More HTML Elements1-06: More HTML Elements
1-06: More HTML Elementsapnwebdev
 
1-05: CSS for Text and Backgrounds
1-05: CSS for Text and Backgrounds1-05: CSS for Text and Backgrounds
1-05: CSS for Text and Backgroundsapnwebdev
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introductionapnwebdev
 
1-02: HTML Markup Introduction
1-02: HTML Markup Introduction1-02: HTML Markup Introduction
1-02: HTML Markup Introductionapnwebdev
 
1-01: Introduction To Web Development
1-01: Introduction To  Web  Development1-01: Introduction To  Web  Development
1-01: Introduction To Web Developmentapnwebdev
 

Mais de apnwebdev (8)

1 05-css for-text_and_backgrounds
1 05-css for-text_and_backgrounds1 05-css for-text_and_backgrounds
1 05-css for-text_and_backgrounds
 
1 04-html elements
1 04-html elements1 04-html elements
1 04-html elements
 
1-07: The Box Model
1-07: The Box Model1-07: The Box Model
1-07: The Box Model
 
1-06: More HTML Elements
1-06: More HTML Elements1-06: More HTML Elements
1-06: More HTML Elements
 
1-05: CSS for Text and Backgrounds
1-05: CSS for Text and Backgrounds1-05: CSS for Text and Backgrounds
1-05: CSS for Text and Backgrounds
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
 
1-02: HTML Markup Introduction
1-02: HTML Markup Introduction1-02: HTML Markup Introduction
1-02: HTML Markup Introduction
 
1-01: Introduction To Web Development
1-01: Introduction To  Web  Development1-01: Introduction To  Web  Development
1-01: Introduction To Web Development
 

Último

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Box Model Guide to Margins, Padding, Borders, and More

Notas do Editor

  1. We've shown you many types of elements, and the subsequent common css properties that change their appearance. Now it's time to learn how they play together - and not just elements of the same type.The document is a crowded place, but through our control and placement, our careful styling, and hopefully a bit of CORRECT rendering display by the browser used - we get a well designed display.How can we control the placement of all these stacked up elements? To do this, we alter some of the properties of css that control how elements interact.
  2. With our last lecture, we've been able to show that tables were logically ordered blocks of code that get organised and drawn little boxes (cells) in an ordered grid. The rules of what make a table organised and displayed in the way it is, is set out by the standards and the browsers that have been designed to use them. We can't override everything in the way something is drawn (because for example, tables are meant to be tables after all) but the more generic an element is, the more pliable it becomes. 
  3. The best way to describe the layout model is with it's common name - the box model. It helps us to visualize what's going on when the document is shown in the browser.Lets illustrate this with an example...
  4.  Lets think of it as a <p> element given the exploded view so we can see it's box model in detail. Lets paraphrase Shrek for a moment:"Elements are like onions, they have layers.“Lets imagine this 'block' element's top and work our way inward, in layers:
  5. Margin [invisible] (pushes other elements away; personal space for elements)
  6. Outline [decorating line] (shares the same space as the margin if you set both)
  7. Border [decorating line] (having it increases the apparent size of the element) 
  8. Padding [invisible space] (also increases apparent size; fills more internal space up!)
  9. And the the content!This includes: ----- Height (and Width) ------
  10. This outside to inside layering happens for top, right, bottom, and left of a block element. Lets look at each in more detail. 
  11. The invisible margin area is like personal space for elements. It keeps other elements pushed a certain amount away from it, or keeps itself away from the edges of immovable boundaries like the browser window size or the element's fixed width and height parent elements. If another element is jostling with this margined element, but it also has a margin... that margin will overlap. Whoever has the largest margin value of those interacting elements, will determine how far they are from each other.
  12. The outline of an element is quite self explanatory in purpose. You're adding an outline of a certain width, colour and density to the bounding dimensions of the element so it kind of looks like a box. Again, the amount of outline is drawn out and away from the width and height boundary.
  13. The outline-style property can be quite decorative actually; with dotted, dashed, solid, double lined, 3d looking grooves, 3d looking ridges, the 3d look of being inset into the page, and the 3d look of outset from the page - all available.Outline is still tricky though, as it shares the space that the Margin uses. If you have a 4px Outline, and a 4px Margin, the final result is a margin overlapping the outline, but that's not going to change the appearance as margin's are invisible space, and outlines are definitely visible. If you have two elements next to each other, the outline of either one will not hesitate to bleed into the space of the other element. The outline is like air in the fact that other elements pass right through it and overlap it regardless if it's there or not. 
  14. This might seem like it's the easiest to tackle because ultimately; this block element is being treated as, a simple rectangle!!By expanding and contracting in two dimensions, we can have the element occupy a space of the document's final rendered view. But, that said... if we add other things like border and padding to the inside of it, we're actually ADDING to the element's final visual dimensions because we're 'filling' it with more space - hence expanding it's boundaries. It's like a balloon in that way.The properties for width and height are:
  15. A lot like the outline, a border is going to let us show a line with the bounds of the element. This time though, the border takes up space inside the bounding dimensions of the width and height. The width of the border actually adds to the size to the final width and height of the element when everything is presented. This happens on the same principle as a balloon - we stretch the balloon to it's width and height, but if we add more contents to it's inside, it's only option is to grow to accommodate that as well. When you're trying to make a box on the screen that contains something, and you want a border, you'll need to deduct those amounts from the final size you're aiming for. It uses it's own space and doesn't share! Eg, i want it to appear as 300px wide... so with a border of 5px set, my value for width should only be 295px. Borders also push content inward, not allowing it to overlap the border.Border-style's have exactly the same decorative properties of outlines; with dotted, dashed, solid, double lined, 3d looking grooves, 3d looking ridges, the 3d look of being inset into the page, and the 3d look of outset from the page.
  16. adding is that little bit of extra cushion we put on an element to separate it's content from the border or outline. It's extra space, on the inside of the element's bounding dimensions, and just like border, adds to the size of the final element if you didn't think about it before specifying your height and width. If we add more padding to the element's inside, it's only option is to grow to accommodate that as well.
  17. Lets recap our layers now with this new found knowledge:
  18. Margin [invisible] (pushes other elements away; personal space for elements)
  19. Outline [decorating line] (shares the same space as the margin if you set both)
  20. Border [decorating line] (having it increases the apparent size of the element) 
  21. Padding [invisible space] (also increases apparent size; fills more internal space up!)
  22. And the the content!This includes: ----- Height (and Width) ------
  23. Once you get to the core of content through all the box model layers, there are a few other properties which come into play in addition to our other known properties for text content etc. 
  24. This is very basically; a certain amount of height, vertically centered over the middle of the text. A large line-height on small text, might have the effect of creating a gap below and above the text evenly between lines. How is this different from padding the text element? Well line-height is not applied to the box of the element, it's on the content - and because of that it affects all lines inside this element of text instead of the sides of the block of text.
  25. For example, setting a line height on a paragraph (<p>...</p>) element will increase the space between each line of text as it flows from left to right. It's essentially the word-processor equivalent to line spacing. These height changes can space or position the text vertically in different places relative to the size of the text, and the design of the font.
  26. This one is simple - it's horizontal alignment of text content inside it's element. left, centered, or right. There's also justification (and it works okay in decent browsers).