Essential Knowledge for Web Development
This presentation covers all the core concepts you need to understand to master HTML and CSS for web development.
Navigate through the slides using the controls at the bottom of the screen or the left and right arrow keys.
Controls how content behaves when it's too large for its container
visible: Content overflows the container (default)hidden: Extra content is clippedscroll: Scrollbars always appearauto: Scrollbars appear only when neededoverlay: Similar to auto (browser-dependent).container {
width: 300px;
height: 200px;
overflow: auto;
border: 1px solid #333;
}
Determines which CSS rule applies when multiple rules target the same element
style="...")#element).class), attribute selectors ([type="text"]), pseudo-classes (:hover)div, p) and pseudo-elements (::before)/* Specificity: 0,0,0,1 */
p { color: black; }
/* Specificity: 0,0,1,1 */
.text p { color: blue; }
/* Specificity: 0,1,0,1 */
#content p { color: red; } /* This one wins */
Describe meaning and purpose rather than just presentation
<header>: Introductory content or navigational links<nav>: Navigation links<main>: Main content of the document (only one per page)<article>: Self-contained content<section>: Thematic grouping of content<aside>: Related but tangential content<footer>: Closing information<header>
<h1>Website Title</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>Article Title</h2>
<p>Content here...</p>
</article>
</main>
<footer>
<p>Copyright 2025</p>
</footer>
Headings create document outline and structure
<h1> - Main page heading (typically one per page)<h2> - Section headings<h3> - Subsection headings<h6><h1>Website Title</h1>
<section>
<h2>Section Heading</h2>
<p>Content...</p>
<h3>Subsection Heading</h3>
<p>More content...</p>
</section>
One-dimensional layout system for rows or columns
display: flexflex-direction: row | column | row-reverse | column-reversejustify-content: Alignment along main axisalign-items: Alignment along cross axisflex-wrap: Controls wrapping of items.container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
flex shorthand combines three properties:
flex-grow: Proportion of available space (number)flex-shrink: How much item will shrink (number)flex-basis: Default size before distributing spaceExamples:
flex: 1 0 auto = grow:1, shrink:0, basis:autoflex: 0 0 200px = fixed width, no growing/shrinking.item-growing {
flex: 1 0 auto; /* Will grow to fill space */
}
.item-fixed {
flex: 0 0 200px; /* Fixed width, won't grow or shrink */
}
.item-flexible {
flex: 1 1 auto; /* Can grow and shrink as needed */
}
Two-dimensional layout system for rows and columns
display: gridgrid-template-columns: Defines column sizesgrid-template-rows: Defines row sizesgrid-gap: Spacing between rows and columnsgrid-template-areas: Named grid areas.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-template-rows: auto auto auto;
grid-gap: 10px;
}
Creates a visual ASCII-like layout of grid cells:
.container {
display: grid;
grid-template-areas:
"header header header"
"sidebar content content"
"footer footer footer";
grid-template-columns: 1fr 3fr 1fr;
grid-gap: 10px;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
Controls how elements are positioned within their containing element
static: Normal flow (default)relative: Positioned relative to its normal positionabsolute: Positioned relative to nearest positioned ancestorfixed: Positioned relative to viewportsticky: Hybrid of relative and fixed.parent {
position: relative;
height: 200px;
}
.child {
position: absolute;
bottom: 0;
right: 0;
/* This places the element at the bottom-right of its parent */
}
Modify the appearance of elements in 2D or 3D space
translate(x, y): Moves elementrotate(angle): Rotates elementscale(x, y): Changes sizeskew(x-angle, y-angle): Skews element.element {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
background-color: blue;
transform: translate(50%, 50%) rotate(45deg);
/* Moves element 50px right and down, then rotates 45 degrees */
}
Basic selectors:
div, p, h1.classname#idname*Combinators:
div p (p inside div)div > p (direct child)h1 + p (p immediately after h1)h1 ~ p (p after h1)Pseudo-classes select elements based on state or position:
:hover, :active, :focus:first-child, :last-child:nth-child(n), :first-of-typePseudo-elements target parts of elements:
::before, ::after (create content)::first-letter, ::first-line::selection (highlighted text)/* First paragraph in an article */
article > p:first-of-type {
font-weight: bold;
}
/* Add decorative first letter */
p::first-letter {
font-size: 2em;
float: left;
padding: 4px;
background-color: red;
}
Apply styles conditionally based on device characteristics
/* Base styles first */
.container {
width: 100%;
}
/* Then conditional styles for larger screens */
@media screen and (min-width: 768px) {
.container {
width: 750px;
margin: 0 auto;
}
}
/* Even larger screens */
@media screen and (min-width: 1200px) {
.container {
width: 1170px;
}
}
Common mistakes:
@media (max-width: 600px) and (min-width: 800px)Techniques for making images adapt to different screen sizes:
/* Basic responsive image */
.responsive-image {
max-width: 100%;
height: auto; /* NOT max-height: auto (invalid) */
}
HTML attributes for responsive images:
<img
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 900px) 800px, 1200px"
src="fallback.jpg"
alt="Description"
>
Set boundaries for element sizing:
min-width: Minimum width element can havemax-width: Maximum width element can havemin-height: Minimum height element can havemax-height: Maximum height element can have.box {
width: 100px; /* Preferred width */
min-width: 150px; /* Overrides width if smaller */
max-width: 200px; /* Maximum allowed width */
}
/* Result: The actual width will be 150px */
Making horizontal navigation menus from lists:
.nav {
display: flex;
list-style: none;
padding: 0;
}
.nav li {
margin-right: 10px;
}
.nav li:hover {
text-decoration: underline;
cursor: pointer;
}
Result: A horizontal navigation menu with items underlined on hover
max-height: auto (invalid, should use height: auto)@media (max-width: 600px) and (min-width: 800px) (impossible condition)flex-direction: horizontal (invalid, should be row)Best practices for accessible forms:
<form>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password">
</div>
<button type="submit">Submit</button>
</form>
Key points:
for and idname attributes for form submissiontype="submit", type="button")Don't just write code:
Common practice techniques:
Practice makes perfect! The best way to understand these concepts is to apply them in your own projects and analyze existing websites.
Remember: Focus on front-end design — backend functionality is not required!