SlideShare una empresa de Scribd logo
1 de 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;
}
}

Más contenido relacionado

Similar a Lecture-8.pptx

Similar a 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
 

Más 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
 

Último

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 

Último (20)

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 

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