CSC336-WT Lec10 Slides
CSC336-WT Lec10 Slides
• Code Snippet:
• css
div {
background-color: lightgrey;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
• html
<div>This text is the content of the box.</div>
CSS3 Box-Sizing Property
• box-sizing: content-box (default) vs box-sizing: border-box
• Example: box-sizing: content-box (default)
#box1 {
box-sizing: content-box;
width: 300px;
height: 100px;
padding: 30px;
border: 10px solid blue;
}
#box2 {
box-sizing: border-box; box-sizing: border-box
width: 300px;
height: 100px;
padding: 30px;
border: 10px solid blue;
}
Website Layout
Content
• 1-column (often used for mobile browsers)
• 2-column (often used for tablets and laptops)
• 3-column layout (only used for desktops)
Float-Based Layouts Overview
Issues:
• clearing floats
• layout breakages
Example: Floats for Layout
• Floats for creating simple layouts
• Code Snippet:
• css
* {
box-sizing: border-box;
}
.left {
float: left;
width: 50%;
padding: 50px;
}
.right {
float: right;
width: 50%;
padding: 50px;
}
• html
<div class="left" style="background-color:#bbbb">Left Column</div>
<div class="right" style="background-color:#cccc">Right Column</div>
Clearfix for Float Layouts
• Using clearfix to avoid float issues
• Code Snippet:
• css
.clearfix::after {
content: "";
display: block;
clear: both;
}
• html
<div class="clearfix">
<div class="left" style="background-color:#aaaa">Left Column</div>
<div class="right" style="background-color:#cccc">Right Column</div>
</div>
3-column layout
/* Create three equal columns that float next to each other */
.column {
float: left;
width: 33.33%;
}
• viewport
• Media Queries
• Flexbox
• Grids
Viewport
Viewport
Viewport
Viewport
<meta name="viewport" content="width=device -width, i n i t i a l - s c a l e = 1 . 0 " >
Media Queries
1 2 3 4 5 6
Flexbox
1 2 3 4 5 6
1 2 3 4 5 6
Flexbox
1 2 3 4 5 6
Flexbox
4 5 6
1 2 3 4 5 6 1 2 3 4 5 6
Flexbox
1 2 3 4 5 6
Flexbox
1 2 3
1 2 3 4 5 6
4 5 6
Flexbox.html
<div id="container">
<div>1. This is some sample text inside of a div to demo Flexbox.</div>
<div>2. This is some sample text inside of a div to demo Flexbox.</div>
<div>3. This is some sample text inside of a div to demo Flexbox.</div>
. . .
<div>12. This is some sample text inside of a div to demo Flexbox.</div>
<div id="container">
#container {
display: flex;
flex-wrap: wrap;
}
#container div {
background-color: springgreen;
font-size: 20px;
margin: 20px;
padding: 20px;
width: 200px;
}
#grid{
background-color: springgreen;
.grid-item{
background-color: white;
font-size: 20px;
padding: 20px;
text-align: center;
}
<div id="grid">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
...
<div class="grid-item">12</div>
<div id="grid">
Adaptive Layouts
•Web designers create layouts for various devices.
•Designers need to develop six different page versions for each device size.
Responsive Layouts Vs Adaptive Layouts
S. No. Responsive Design Adaptive Design
It adjusts its content and width according to the According to the device, it loads the content of the
1.
device. web page that was already designed.
Designers have to work more because they have to
Designers have to work less because they have to
2. create six different versions of the site to handle
create the single layout of the page designers
different screen sizes.
If there is any new layout of the screen comes into
Designers have to develop a completely new page if
3. the market, the content is adjusted according to
the new layout of the screen has come into the market.
them.
Responsive Design works well for larger sites that Adaptive Design works well for smaller sites that are
4.
are being built from the scratch. being refreshed.
Examples-
• Slack Examples-
5. • Dropbox • Apple
• Github • Amazon
• Shopify
Mobile-First
Approach
Overview
• Start designing for
mobile devices first
• Progressive
enhancement for larger
screens
• Example of typical min-
width media queries
Example: Mobile-First Design
• Code Snippet:
• css
.column {
width: 100%; /* Occupy 100% of the container width */
}