SlideShare a Scribd company logo
1 of 40
Advanced CSS
Jayapadmini Kanchan
Dept. of ISE
Normal Flow
• Browsers will normally displays block-level
elements and inline elements from left to
right and from top to bottom
• Block level elements such as <div> <table> etc
are contained on their own line
• Inline elements do not form their own blocks
but instead are displayed within lines such as
<em> <a> <span>
Block-level Elements
• A block-level element always starts on a new
line and takes up the full width available
(stretches out to the left and right as far as it
can).
• The <div> element is a block-level element.
Inline Elements
• An inline element does not start on a new line
and only takes up as much width as necessary.
• This is an inline <span> element inside a
paragraph.
Positioning Elements
• The position property specifies the type of
positioning method used for an element.
• The types of positioning elements are
• relative
• fixed
• Absolute
• Static
Static Positioning
• This is the default for every single page element.
• Different elements don't have different default values for
positioning, they all start out as static.
• Static doesn't mean much; it just means that the element will
flow into the page as it normally would.
• The only reason you would ever set an element to position:
static; is to forcefully remove some positioning that got
applied to an element outside of your control.
Fixed Positioning
• A fixed position element is positioned relative to the viewport,
or the browser window itself.
• The viewport doesn't change when the window is scrolled, so a
fixed positioned element will stay right where it is when the
page is scrolled
• The top, right, bottom, and left properties are used to position
the element.
• A fixed element does not leave a gap in the page where it
would normally have been located.
Relative Positioning
 An element with position: relative; is positioned relative to its
normal position
 Setting the top, right, bottom, and left properties of a
relatively-positioned element will cause it to be adjusted away
from its normal position.
 If you set position: relative; on an element but no other
positioning attributes (top, left, bottom or right), it will no
effect on it's positioning at all, it will be exactly as it would be
if you left it as position: static; But if you do give it some other
positioning attribute, say, top: 10px;, it will shift its position 10
pixels up from where it would normally be.
Absolute Positioning
• An element with position: absolute; is positioned relative to
the nearest positioned ancestor
• This is a very powerful type of positioning that allows you to
literally place any page element exactly where you want it.
• You use the positioning attributes top, left, bottom. and right to
set the location.
• If an absolute positioned element has no positioned ancestors,
it uses the document body, and moves along with page
scrolling.vwport, like fixed).
Z-index
• The z-index property specifies the stack order of an element.
• An element with greater stack order is always in front of an
element with a lower stack order.
• z-index only works on positioned elements (position:absolute,
position:relative, or position:fixed).
Floating Elements
• The CSS float property specifies how an element should
float.
• The CSS clear property specifies what elements can float
beside the cleared element and on which side.
The float property can have one of the following values:
• left - The element floats to the left of its container
• right- The element floats to the right of its container
• none - The element does not float (will be displayed just
where it occurs in the text). This is default
• inherit - The element inherits the float value of its parent
• In its simplest use, the float property can be used to wrap
text around images.
Clear Property
• The clear property specifies what elements can float beside
the cleared element and on which side
• The clear property can have one of the following values:
• none - Allows floating elements on both sides. This is
default
• left - No floating elements allowed on the left side
• right- No floating elements allowed on the right side
• both - No floating elements allowed on either the left or the
right side
• inherit - The element inherits the clear value of its parent
div4 {
border: 1px solid red;
clear: left;
}
Clearfix
• If an element is taller than the element
containing it, and it is floated, it will "overflow"
outside of its container:
• Then we can add overflow: auto; to the
containing element to fix this problem:
• The overflow: auto clearfix works well as long as
you are able to keep control of your margins and
padding
• The new, modern clearfix hack however, is safer
to use, and the following code is used for most
webpages:
Clearfix
clearfix {
overflow: auto;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
Overlaying and hiding elements
• Hiding an element can be done by setting
the display property to none. The element will
be hidden, and the page will be displayed as if
the element is not there
• <!DOCTYPE html>
• <html>
• <body>
• <h2>What Can JavaScript Do?</h2>
• <p id="demo">JavaScript can hide HTML elements.</p>
• <button type="button"
onclick="document.getElementById('demo').style.display='none'">Click
Me!</button>
• </body>
• </html>
Multicolumn layouts
Multi Column Layouts
• There are two different ways to move items
out of the normal top-down flow, namely,
• Positioning
• Floats
• A typical layout may use both positioning and
floats for multicolumn layouts
Using floats to create columns
• The most common way to create a column of
content is with the help of floats
• The first step is to float the content ,container
that will be on the left hand side.
Using positioning to create columns
• Positioning can also be used to create multi
column layouts
• First step is to position the floated elements.
Approaches to CSS layout
The table-layout property defines the algorithm
used to lay out table cells, rows, and columns.
Syntax:
table-layout: auto | fixed | initial |inherit;
Two basic models
Fixed Layout
Liquid Layout
Other layout approach(hybrid)
Fixed Layout
• In fixed layout, the basic width is set by
designer
• Fixed layout are created using pixel units
typically with entire content within <div>
container
Advantage:
• Easier to produce and generally have a
predictable visual result
Disadvantage:
• For larger screen, there may be an excessive
amount of blank space to the left & right of
the content
• When browser window shrinks below the
fixed width; the user will have to horizontally
scroll to see all the content
table.a {
table-layout: auto;
width: 180px;
}
table.b {
table-layout: fixed;
width: 180px;
}
Liquid Layout
• Second approach dealing with the problem of
multiple screen sizes is to use fluid (liquid)
layout
• Width are not specified using pixels, but
percentage values
Advantage
• Adapt to different browser sizes, neither
wasted white space nor ant need for
horizontal scrolling
Responsive Design
• In responsive design ,the page “responds” to changes
in the browser size that go beyond the width scaling
of a liquid layout
• Responsive Web Design is about using HTML and CSS
to automatically resize, hide, shrink, or enlarge, a
website, to make it look good on all devices
(desktops, tablets, and phones):
Responsive Layout
Key Components
a. Liquid Layout
b. Scaling images to the viewport size
c. Setting viewport via the <meta> tag
d. Customizing the CSS for different viewports
using media queries
img{
Max-width: 100%;
}
Setting viewports
• When making responsive web pages, add the
following <meta> element in all your web pages:
<meta name="viewport" content="width=device-
width/">
• This will set the viewport of your page, which will
give the browser instructions on how to control the
page's dimensions and scaling.
• Here is an example of a web page without the
viewport meta tag, and the same web
page with the viewport meta tag:
Media Queries
• 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.
• In addition to resize text and images, it is also
common to use media queries in responsive web
pages.
• With media queries you can define completely
different styles for different browser sizes.
• Example: resize the browser window to see
that the three div elements below will display
horizontally on large screens and stacked
vertically on small screens:
Browser Features with media query
• Width- width of the viewport
• Height- height of the viewport
• Device-width –width of the device
• Device-height- height of the device
• Orientation- Whether the device is portrait or
landscape
• Color- the number of bits per color
CSS Framework
Two main types of CSS Framework
• Grid system
• CSS preprocessor
Grid System
• The CSS Grid Layout Module offers a grid-
based layout system, with rows and columns,
making it easier to design web pages without
having to use floats and positioning
• Easy to create multicolumn layout
• Most popular are Bootstrap's grid system,
blueprint etc.
• To achieve visual uniformity in a design
CSS Preprocessors
• CSS Preprocessors are tools that allow the
developer to write CSS that takes advantage of
programming ideas such as variable,
inheritance, calculations and functions
• It Can provide additional functionalities that
are not in CSS

More Related Content

Similar to Advanced CSS Techniques

Similar to Advanced CSS Techniques (20)

CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
 
CSS3 PPT.pptx
CSS3 PPT.pptxCSS3 PPT.pptx
CSS3 PPT.pptx
 
CSS_Dibbo
CSS_DibboCSS_Dibbo
CSS_Dibbo
 
Lecture2 CSS 3
Lecture2   CSS 3Lecture2   CSS 3
Lecture2 CSS 3
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Chapter4 mo
Chapter4 moChapter4 mo
Chapter4 mo
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
 
WEBD 162: display property, Float and Clear
WEBD 162: display property, Float and ClearWEBD 162: display property, Float and Clear
WEBD 162: display property, Float and Clear
 
css.pdf
css.pdfcss.pdf
css.pdf
 
Cascading Style Sheets CSS
Cascading Style Sheets CSS Cascading Style Sheets CSS
Cascading Style Sheets CSS
 
Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)
 
Cross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazineCross Browser Issues - few solutions inspired by smashing magazine
Cross Browser Issues - few solutions inspired by smashing magazine
 
Code & Design your first website 4/18
Code & Design your first website 4/18Code & Design your first website 4/18
Code & Design your first website 4/18
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)
 
HTML and CSS part 3
HTML and CSS part 3HTML and CSS part 3
HTML and CSS part 3
 
HTML5- Create divisions in a web page
HTML5- Create divisions in a web pageHTML5- Create divisions in a web page
HTML5- Create divisions in a web page
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
ADF - Layout Managers and Skinning
ADF - Layout Managers and SkinningADF - Layout Managers and Skinning
ADF - Layout Managers and Skinning
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 

Recently uploaded (20)

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 

Advanced CSS Techniques

  • 2.
  • 3. Normal Flow • Browsers will normally displays block-level elements and inline elements from left to right and from top to bottom • Block level elements such as <div> <table> etc are contained on their own line • Inline elements do not form their own blocks but instead are displayed within lines such as <em> <a> <span>
  • 4. Block-level Elements • A block-level element always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can). • The <div> element is a block-level element.
  • 5. Inline Elements • An inline element does not start on a new line and only takes up as much width as necessary. • This is an inline <span> element inside a paragraph.
  • 6.
  • 7. Positioning Elements • The position property specifies the type of positioning method used for an element. • The types of positioning elements are • relative • fixed • Absolute • Static
  • 8. Static Positioning • This is the default for every single page element. • Different elements don't have different default values for positioning, they all start out as static. • Static doesn't mean much; it just means that the element will flow into the page as it normally would. • The only reason you would ever set an element to position: static; is to forcefully remove some positioning that got applied to an element outside of your control.
  • 9. Fixed Positioning • A fixed position element is positioned relative to the viewport, or the browser window itself. • The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled • The top, right, bottom, and left properties are used to position the element. • A fixed element does not leave a gap in the page where it would normally have been located.
  • 10. Relative Positioning  An element with position: relative; is positioned relative to its normal position  Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position.  If you set position: relative; on an element but no other positioning attributes (top, left, bottom or right), it will no effect on it's positioning at all, it will be exactly as it would be if you left it as position: static; But if you do give it some other positioning attribute, say, top: 10px;, it will shift its position 10 pixels up from where it would normally be.
  • 11. Absolute Positioning • An element with position: absolute; is positioned relative to the nearest positioned ancestor • This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. • You use the positioning attributes top, left, bottom. and right to set the location. • If an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.vwport, like fixed).
  • 12. Z-index • The z-index property specifies the stack order of an element. • An element with greater stack order is always in front of an element with a lower stack order. • z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
  • 13. Floating Elements • The CSS float property specifies how an element should float. • The CSS clear property specifies what elements can float beside the cleared element and on which side. The float property can have one of the following values: • left - The element floats to the left of its container • right- The element floats to the right of its container • none - The element does not float (will be displayed just where it occurs in the text). This is default • inherit - The element inherits the float value of its parent • In its simplest use, the float property can be used to wrap text around images.
  • 14.
  • 15. Clear Property • The clear property specifies what elements can float beside the cleared element and on which side • The clear property can have one of the following values: • none - Allows floating elements on both sides. This is default • left - No floating elements allowed on the left side • right- No floating elements allowed on the right side • both - No floating elements allowed on either the left or the right side • inherit - The element inherits the clear value of its parent
  • 16. div4 { border: 1px solid red; clear: left; }
  • 17. Clearfix • If an element is taller than the element containing it, and it is floated, it will "overflow" outside of its container: • Then we can add overflow: auto; to the containing element to fix this problem: • The overflow: auto clearfix works well as long as you are able to keep control of your margins and padding • The new, modern clearfix hack however, is safer to use, and the following code is used for most webpages:
  • 18. Clearfix clearfix { overflow: auto; } .clearfix::after { content: ""; clear: both; display: table; }
  • 19. Overlaying and hiding elements • Hiding an element can be done by setting the display property to none. The element will be hidden, and the page will be displayed as if the element is not there
  • 20. • <!DOCTYPE html> • <html> • <body> • <h2>What Can JavaScript Do?</h2> • <p id="demo">JavaScript can hide HTML elements.</p> • <button type="button" onclick="document.getElementById('demo').style.display='none'">Click Me!</button> • </body> • </html>
  • 22. Multi Column Layouts • There are two different ways to move items out of the normal top-down flow, namely, • Positioning • Floats • A typical layout may use both positioning and floats for multicolumn layouts
  • 23. Using floats to create columns • The most common way to create a column of content is with the help of floats • The first step is to float the content ,container that will be on the left hand side.
  • 24. Using positioning to create columns • Positioning can also be used to create multi column layouts • First step is to position the floated elements.
  • 25. Approaches to CSS layout The table-layout property defines the algorithm used to lay out table cells, rows, and columns. Syntax: table-layout: auto | fixed | initial |inherit; Two basic models Fixed Layout Liquid Layout Other layout approach(hybrid)
  • 26. Fixed Layout • In fixed layout, the basic width is set by designer • Fixed layout are created using pixel units typically with entire content within <div> container Advantage: • Easier to produce and generally have a predictable visual result
  • 27. Disadvantage: • For larger screen, there may be an excessive amount of blank space to the left & right of the content • When browser window shrinks below the fixed width; the user will have to horizontally scroll to see all the content
  • 28. table.a { table-layout: auto; width: 180px; } table.b { table-layout: fixed; width: 180px; }
  • 29. Liquid Layout • Second approach dealing with the problem of multiple screen sizes is to use fluid (liquid) layout • Width are not specified using pixels, but percentage values Advantage • Adapt to different browser sizes, neither wasted white space nor ant need for horizontal scrolling
  • 30. Responsive Design • In responsive design ,the page “responds” to changes in the browser size that go beyond the width scaling of a liquid layout • Responsive Web Design is about using HTML and CSS to automatically resize, hide, shrink, or enlarge, a website, to make it look good on all devices (desktops, tablets, and phones):
  • 32. Key Components a. Liquid Layout b. Scaling images to the viewport size c. Setting viewport via the <meta> tag d. Customizing the CSS for different viewports using media queries img{ Max-width: 100%; }
  • 33. Setting viewports • When making responsive web pages, add the following <meta> element in all your web pages: <meta name="viewport" content="width=device- width/"> • This will set the viewport of your page, which will give the browser instructions on how to control the page's dimensions and scaling. • Here is an example of a web page without the viewport meta tag, and the same web page with the viewport meta tag:
  • 34.
  • 35. Media Queries • 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. • In addition to resize text and images, it is also common to use media queries in responsive web pages. • With media queries you can define completely different styles for different browser sizes.
  • 36. • Example: resize the browser window to see that the three div elements below will display horizontally on large screens and stacked vertically on small screens:
  • 37. Browser Features with media query • Width- width of the viewport • Height- height of the viewport • Device-width –width of the device • Device-height- height of the device • Orientation- Whether the device is portrait or landscape • Color- the number of bits per color
  • 38. CSS Framework Two main types of CSS Framework • Grid system • CSS preprocessor
  • 39. Grid System • The CSS Grid Layout Module offers a grid- based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning • Easy to create multicolumn layout • Most popular are Bootstrap's grid system, blueprint etc. • To achieve visual uniformity in a design
  • 40. CSS Preprocessors • CSS Preprocessors are tools that allow the developer to write CSS that takes advantage of programming ideas such as variable, inheritance, calculations and functions • It Can provide additional functionalities that are not in CSS