James Williams
Birmingham Newman University
jwilliams@staff.newman.ac.uk
3-hour session
.box {
width: 200px;
height: 100px;
padding: 20px;
border: 2px solid black;
margin: 10px;
}
Margin: 10px
Border: 3px solid
Padding: 20px
Content: 200px × 100px
Drag the sliders to see how margin, border, and padding affect the box model!
/* Default behavior */
.default-box {
box-sizing: content-box;
width: 200px;
padding: 20px;
border: 2px solid black;
/* Total width = 200 + 40 + 4 = 244px */
}
/* Include padding and border in width */
.border-box {
box-sizing: border-box;
width: 200px;
padding: 20px;
border: 2px solid black;
/* Total width = 200px */
}
/* Block elements */
.block { display: block; }
/* Inline elements */
.inline { display: inline; }
/* Inline-block elements */
.inline-block { display: inline-block; }
/* Hidden elements */
.hidden { display: none; }
/* Table elements */
.table { display: table; }
.table-cell { display: table-cell; }
/* Static (default) */
.static { position: static; }
/* Relative */
.relative { position: relative; top: 10px; left: 20px; }
/* Absolute */
.absolute { position: absolute; top: 0; right: 0; }
/* Fixed */
.fixed { position: fixed; bottom: 20px; right: 20px; }
/* Sticky */
.sticky { position: sticky; top: 0; }
.relative-box {
position: relative;
top: 20px;
left: 30px;
background: #e7f3ff;
border: 2px solid #007bff;
padding: 15px;
}
.container {
position: relative;
height: 200px;
border: 2px solid #333;
}
.absolute-box {
position: absolute;
top: 20px;
right: 20px;
background: #ffc107;
padding: 10px;
}
.fixed-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #333;
color: white;
z-index: 1000;
}
.fixed-button {
position: fixed;
bottom: 20px;
right: 20px;
background: #007bff;
color: white;
padding: 15px;
border-radius: 50%;
}
.background {
z-index: 1;
background: #e7f3ff;
}
.middle {
z-index: 2;
background: #ffc107;
}
.foreground {
z-index: 3;
background: #dc3545;
}
.float-left {
float: left;
width: 200px;
margin-right: 20px;
}
.float-right {
float: right;
width: 200px;
margin-left: 20px;
}
.clearfix::after {
content: "";
display: table;
clear: both;
}
.clear-left { clear: left; }
.clear-right { clear: right; }
.clear-both { clear: both; }
.clear-none { clear: none; }
/* Modern clearfix */
.clearfix::after {
content: "";
display: table;
clear: both;
}
left: Clear left floatsright: Clear right floatsboth: Clear both sides/* Mobile first approach */
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
/* Tablet styles */
@media (min-width: 768px) {
.container {
padding: 0 20px;
}
}
/* Desktop styles */
@media (min-width: 1024px) {
.container {
padding: 0 40px;
}
}
/* Small screens */
@media (max-width: 767px) {
.sidebar { display: none; }
.main { width: 100%; }
}
/* Medium screens */
@media (min-width: 768px) and (max-width: 1023px) {
.sidebar { width: 200px; }
.main { width: calc(100% - 200px); }
}
/* Large screens */
@media (min-width: 1024px) {
.sidebar { width: 250px; }
.main { width: calc(100% - 250px); }
}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
width=device-width: Match viewport to device widthinitial-scale=1.0: Set initial zoom levellayout-practice.htmlTime: 45 minutes
This task will help you understand CSS layout and positioning
Take a break, ask questions, or catch up on the previous task.
Next: Secondary slides and Task 2
/* CSS Reset - removes all defaults */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Normalize - preserves useful defaults */
/* Use normalize.css for better cross-browser consistency */
/* Debug with borders */
* { border: 1px solid red !important; }
responsive-layout.htmlTime: 45 minutes
This task will help you understand responsive design and media queries
.grid-container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-gap: 20px;
}
.grid-item {
background: #e7f3ff;
padding: 20px;
}
CSS Flexbox and Grid - Modern layout techniques