SlideShare une entreprise Scribd logo
1  sur  16
CSS Box Model
CSS Box Model
 All HTML elements can be considered as boxes.
 In CSS, the term "box model" is used when
talking about design and layout.
 The CSS box model is essentially a box that
wraps around every HTML element. It consists of:
margins, borders, padding, and the actual
content.
Explanation of the different parts:
 Content - The content of the box, where text and
images appear
 Padding - Clears an area around the content.
The padding is transparent
 Border - A border that goes around the padding
and content
 Margin - Clears an area outside the border. The
margin is transparent
Demonstration of the box model:
div {
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
Width and Height of an Element
 In order to set the width and height of an element
correctly in all browsers, you need to know how
the box model works.
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
Here is the calculation:
This <div> element will have a total
width of 350px:
The total width of an element should be calculated like this:
Total element width = width + left padding + right padding + left border + right
border + left margin + right margin
The total height of an element should be calculated like this:
Total element height = height + top padding + bottom padding + top border +
bottom border + top margin + bottom margin
CSS position
 The position property specifies the type of positioning
method used for an element (static, relative, absolute,
fixed, or sticky).
position: static|absolute|fixed|relative|sticky|initial|inherit;
static Default value. Elements render in order, as they appear in the
document flow
absolute The element is positioned relative to its first positioned (not static)
ancestor element
fixed The element is positioned relative to the browser window
relative The element is positioned relative to its normal position, so "left:20px"
adds 20 pixels to the element's LEFT position
sticky The element is positioned based on the user's scroll positionA sticky
element toggles between relative and fixed, depending on the scroll
position. It is positioned relative until a given offset position is met in
the viewport - then it "sticks" in place (like position:fixed).
Note: Not supported in IE/Edge 15 or earlier. Supported in Safari from
version 6.1 with a -webkit- prefix.
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
Position an <h2> element:
h2 {
position: absolute;
left: 100px;
top: 150px;
}
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position: relative;
left: 20px;
}
#parent1 {
position: static;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child1 {
position: absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
#parent2 {
position: relative;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child2 {
position: absolute;
border: 1px solid red;
top: 70px;
right: 15px;}
CSS float
The float property specifies whether an element
should float to the left, right, or not at all.
 Note: Absolutely positioned elements ignore
the float property!
 Note: Elements next to a floating element will flow
around it.
none The element does not float, (will be displayed just where
it occurs in the text). This is default
left The element floats to the left of its container
right The element floats the right of its container
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
float: none|left|right|initial|inherit;
img {
float: right;
}
img {
float: left;
}
img {
float: none;
}
.header, .footer {
background-color: grey;
color: white;
padding: 15px;
}
.column {
float: left;
padding: 15px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.menu {width: 25%;}
.content {width: 75%;}
CSS display
 The display property specifies the display behavior (the
type of rendering box) of an element.
 In HTML, the default display property value is taken
from the HTML specifications or from the browser/user
default style sheet. The default value in XML is inline,
including SVG elements.
p.ex1 {display: none;}
p.ex2 {display: inline;}
p.ex3 {display: block;}
p.ex4 {display: inline-block;}
inline Displays an element as an inline
element (like <span>). Any height and
width properties will have no effect
block Displays an element as a block
element (like <p>). It starts on a new
line, and takes up the whole width
contents Makes the container disappear,
making the child elements children of
the element the next level up in the
DOM
flex Displays an element as a block-level
flex container
grid Displays an element as a block-level
grid container
inline-
block
Displays an element as an inline-level
block container. The element itself is
formatted as an inline element, but
you can apply height and width
values
inline-flex Displays an element as an inline-level
flex container
inline-grid Displays an element as an inline-level
grid container
inline-table The element is displayed as an inline-
level table
list-item Let the element behave like a <li>
element
run-in Displays an element as either
block or inline, depending on
context
table Let the element behave like a
<table> element
table-
caption
Let the element behave like a
<caption> element
table-
column-
group
Let the element behave like a
<colgroup> element
table-
header-
group
Let the element behave like a
<thead> element
table-
footer-
group
Let the element behave like a
<tfoot> element
table-row-
group
Let the element behave like a
<tbody> element
table-cell Let the element behave like a
<td> element
table-
column
Let the element behave like a
<col> element
table-row Let the element behave like a
<tr> element
none The element is completely
removed
initial Sets this property to its default
body {
display: inline;
}
p {
display: inherit;
}
div {
display: flex;
flex-direction: row-
reverse;
}
Media Query
 Media query is a CSS technique introduced in CSS3.
 It uses the @media rule to include a block of CSS
properties only if a certain condition is true.
 If the browser window is 600px or smaller, the
background color will be lightblue:
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
When the screen (browser window) gets smaller than 768px,
each column should have a width of 100%:
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
 @media only screen and (max-width:
768px) {
/* For mobile phones: */
[class*="col-"] {
width: 100%;
}
}
Orientation: Portrait / Landscape
 Media queries can also be
used to change layout of a
page depending on the
orientation of the browser.
 You can have a set of CSS
properties that will only
apply when the browser
window is wider than its
height, a so called
"Landscape" orientation:
The web page will have a lightblue
background if the orientation is in
landscape mode:
 Another common use
of media queries, is to
hide elements on
different screen sizes:
/* If the screen size is 600px wide or less,
hide the element */
@media only screen and (max-width:
600px) {
div.example {
display: none;
}
}
@media only screen and (orientation: landscape) {
body {
background-color: lightblue;
}}
You can also use media queries to change the font
size of an element on different screen sizes:
/* If the screen size is 601px or more, set the font-size of <div>
to 80px */
@media only screen and (min-width: 601px) {
div.example {
font-size: 80px;
}
}
/* If the screen size is 600px or less, set the font-
size of <div> to 30px */
@media only screen and (max-width: 600px) {
div.example {
font-size: 30px;
}
}

Contenu connexe

Similaire à Lecture-8.pptx

Similaire à Lecture-8.pptx (20)

Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
 
Css3
Css3Css3
Css3
 
Advanced CSS Tricks and Techniques
Advanced CSS Tricks and TechniquesAdvanced CSS Tricks and Techniques
Advanced CSS Tricks and Techniques
 
Html frames
Html framesHtml frames
Html frames
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Class 10
Class 10Class 10
Class 10
 
INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2INTRODUCTIONS OF CSS PART 2
INTRODUCTIONS OF CSS PART 2
 
CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learner
 
New CSS Meets the Real World
New CSS Meets the Real WorldNew CSS Meets the Real World
New CSS Meets the Real World
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
But what about old browsers?
But what about old browsers?But what about old browsers?
But what about old browsers?
 
CSS3 Refresher
CSS3 RefresherCSS3 Refresher
CSS3 Refresher
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 
CSS
CSSCSS
CSS
 
Grid and Flexbox - Smashing Conf SF
Grid and Flexbox - Smashing Conf SFGrid and Flexbox - Smashing Conf SF
Grid and Flexbox - Smashing Conf SF
 
CSS-3 Course Slide
CSS-3 Course SlideCSS-3 Course Slide
CSS-3 Course Slide
 

Plus de vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Dernier

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Dernier (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Lecture-8.pptx

  • 2. CSS Box Model  All HTML elements can be considered as boxes.  In CSS, the term "box model" is used when talking about design and layout.  The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.
  • 3. Explanation of the different parts:  Content - The content of the box, where text and images appear  Padding - Clears an area around the content. The padding is transparent  Border - A border that goes around the padding and content  Margin - Clears an area outside the border. The margin is transparent
  • 4. Demonstration of the box model: div { width: 300px; border: 15px solid green; padding: 50px; margin: 20px; }
  • 5. Width and Height of an Element  In order to set the width and height of an element correctly in all browsers, you need to know how the box model works. div { width: 320px; padding: 10px; border: 5px solid gray; margin: 0; } 320px (width) + 20px (left + right padding) + 10px (left + right border) + 0px (left + right margin) = 350px Here is the calculation: This <div> element will have a total width of 350px: The total width of an element should be calculated like this: Total element width = width + left padding + right padding + left border + right border + left margin + right margin The total height of an element should be calculated like this: Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
  • 6. CSS position  The position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky). position: static|absolute|fixed|relative|sticky|initial|inherit; static Default value. Elements render in order, as they appear in the document flow absolute The element is positioned relative to its first positioned (not static) ancestor element fixed The element is positioned relative to the browser window relative The element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position sticky The element is positioned based on the user's scroll positionA sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed). Note: Not supported in IE/Edge 15 or earlier. Supported in Safari from version 6.1 with a -webkit- prefix. initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 7. Position an <h2> element: h2 { position: absolute; left: 100px; top: 150px; } h2.pos_left { position: relative; left: -20px; } h2.pos_right { position: relative; left: 20px; } #parent1 { position: static; border: 1px solid blue; width: 300px; height: 100px; } #child1 { position: absolute; border: 1px solid red; top: 70px; right: 15px; } #parent2 { position: relative; border: 1px solid blue; width: 300px; height: 100px; } #child2 { position: absolute; border: 1px solid red; top: 70px; right: 15px;}
  • 8. CSS float The float property specifies whether an element should float to the left, right, or not at all.  Note: Absolutely positioned elements ignore the float property!  Note: Elements next to a floating element will flow around it. none The element does not float, (will be displayed just where it occurs in the text). This is default left The element floats to the left of its container right The element floats the right of its container initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 9. float: none|left|right|initial|inherit; img { float: right; } img { float: left; } img { float: none; } .header, .footer { background-color: grey; color: white; padding: 15px; } .column { float: left; padding: 15px; } .clearfix::after { content: ""; clear: both; display: table; } .menu {width: 25%;} .content {width: 75%;}
  • 10. CSS display  The display property specifies the display behavior (the type of rendering box) of an element.  In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet. The default value in XML is inline, including SVG elements. p.ex1 {display: none;} p.ex2 {display: inline;} p.ex3 {display: block;} p.ex4 {display: inline-block;}
  • 11. inline Displays an element as an inline element (like <span>). Any height and width properties will have no effect block Displays an element as a block element (like <p>). It starts on a new line, and takes up the whole width contents Makes the container disappear, making the child elements children of the element the next level up in the DOM flex Displays an element as a block-level flex container grid Displays an element as a block-level grid container inline- block Displays an element as an inline-level block container. The element itself is formatted as an inline element, but you can apply height and width values inline-flex Displays an element as an inline-level flex container inline-grid Displays an element as an inline-level grid container inline-table The element is displayed as an inline- level table list-item Let the element behave like a <li> element run-in Displays an element as either block or inline, depending on context table Let the element behave like a <table> element table- caption Let the element behave like a <caption> element table- column- group Let the element behave like a <colgroup> element table- header- group Let the element behave like a <thead> element table- footer- group Let the element behave like a <tfoot> element table-row- group Let the element behave like a <tbody> element table-cell Let the element behave like a <td> element table- column Let the element behave like a <col> element table-row Let the element behave like a <tr> element none The element is completely removed initial Sets this property to its default
  • 12. body { display: inline; } p { display: inherit; } div { display: flex; flex-direction: row- reverse; }
  • 13. Media Query  Media query is a CSS technique introduced in CSS3.  It uses the @media rule to include a block of CSS properties only if a certain condition is true.  If the browser window is 600px or smaller, the background color will be lightblue: @media only screen and (max-width: 600px) { body { background-color: lightblue; } }
  • 14. When the screen (browser window) gets smaller than 768px, each column should have a width of 100%: /* For desktop: */ .col-1 {width: 8.33%;} .col-2 {width: 16.66%;} .col-3 {width: 25%;} .col-4 {width: 33.33%;} .col-5 {width: 41.66%;} .col-6 {width: 50%;} .col-7 {width: 58.33%;} .col-8 {width: 66.66%;} .col-9 {width: 75%;} .col-10 {width: 83.33%;} .col-11 {width: 91.66%;} .col-12 {width: 100%;}  @media only screen and (max-width: 768px) { /* For mobile phones: */ [class*="col-"] { width: 100%; } }
  • 15. Orientation: Portrait / Landscape  Media queries can also be used to change layout of a page depending on the orientation of the browser.  You can have a set of CSS properties that will only apply when the browser window is wider than its height, a so called "Landscape" orientation: The web page will have a lightblue background if the orientation is in landscape mode:  Another common use of media queries, is to hide elements on different screen sizes: /* If the screen size is 600px wide or less, hide the element */ @media only screen and (max-width: 600px) { div.example { display: none; } } @media only screen and (orientation: landscape) { body { background-color: lightblue; }}
  • 16. You can also use media queries to change the font size of an element on different screen sizes: /* If the screen size is 601px or more, set the font-size of <div> to 80px */ @media only screen and (min-width: 601px) { div.example { font-size: 80px; } } /* If the screen size is 600px or less, set the font- size of <div> to 30px */ @media only screen and (max-width: 600px) { div.example { font-size: 30px; } }