SlideShare ist ein Scribd-Unternehmen logo
1 von 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;
}
}

Weitere ähnliche Inhalte

Ähnlich wie Lecture-8.pptx

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Kürzlich hochgeladen (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

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; } }