The Ultimate CSS Guide

The Ultimate CSS Guide: From Basics to Advanced Techniques​


📌 Part 1: CSS Fundamentals​


1. What is CSS?​

CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of HTML documents. It controls layout, colors, fonts, and responsive designs.

2. Adding CSS to HTML​

There are three ways to apply CSS:
Inline CSS (directly in HTML elements):

HTML:
<p style="color: blue;">This is blue text</p>

Internal CSS (in the <head> section):

HTML:
<head>
<style>
p {
color: blue;
}
  </style>
</head>


External CSS (separate .css file):

HTML:
<head>
<link rel="stylesheet" href="styles.css">
</head>

styles.css:

CSS:
p {
color: blue;
}

3. Basic CSS Syntax​


CSS:
selector {
property: value;
}

Example:

CSS:
h1 {
color: #ff0000;
font-size: 24px;
text-align: center;
}

4. Common CSS Properties​


CSS:
/* Text styling */
p {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
text-decoration: underline;
}

/* Colors */
body {
color: #333;          /* Text color */
background-color: #f5f5f5; /* Background color */
}

/* Box model */
div {
width: 300px;
height: 200px;
padding: 20px;
margin: 10px;
border: 1px solid #ccc;
}

📌 Part 2: Intermediate CSS​

5. CSS Selectors​

Basic Selectors:

CSS:
/* Element selector */
p { color: blue; }

/* Class selector */
.highlight { background: yellow; }

/* ID selector */
#header { height: 100px; }

Advanced Selectors:

CSS:
/* Descendant selector */
article p { font-style: italic; }

/* Child selector */
ul > li { list-style: none; }

/* Attribute selector */
a[target="_blank"] { color: red; }

/* Pseudo-classes */
a:hover { text-decoration: none; }
li:nth-child(odd) { background: #eee; }

6. The Box Model​

Every element is a box with:
  • Content
  • Padding (inner space)
  • Border
  • Margin (outer space)
CSS:
.box {
box-sizing: border-box; /* Includes padding/border in width */
width: 300px;
padding: 20px;
border: 5px solid black;
margin: 10px;
}

7. Positioning Elements​

CSS:
/* Static (default) */
.static { position: static; }

/* Relative to normal position */
.relative { position: relative; top: 20px; }

/* Absolute (relative to nearest positioned ancestor) */
.absolute { position: absolute; right: 0; }

/* Fixed (relative to viewport) */
.fixed { position: fixed; bottom: 0; }

/* Sticky */
.sticky { position: sticky; top: 0; }


📌 Part 3: Advanced CSS​

8. Flexbox Layout​

CSS:
.container {
display: flex;
justify-content: center; /* Main axis alignment */
align-items: center;    /* Cross axis alignment */
flex-wrap: wrap;       /* Allow wrapping */
}

.item {
flex: 1;               /* Grow/shrink equally */
min-width: 200px;
}

9. CSS Grid Layout​

CSS:
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
}

.grid-item {
grid-column: span 2; /* Span 2 columns */
}

10. Animations & Transitions​

Transitions:
CSS:
.button {
transition: all 0.3s ease;
}
.button:hover {
transform: scale(1.1);
background: #4CAF50;
}

Animations:
CSS:
@keyframes slidein {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}

.slide {
animation: slidein 1s forwards;
}

📌 Part 4: Modern CSS Techniques​

11. Responsive Design​

CSS:
/* Media queries */
@media (max-width: 768px) {
.menu { display: none; }
.mobile-menu { display: block; }
}

/* Responsive units */
.container {
width: 90%;
max-width: 1200px;
margin: 0 auto;
}

img {
max-width: 100%;
height: auto;
}

12. CSS Variables​

CSS:
:root {
--primary-color: #3498db;
--spacing: 20px;
}

.box {
color: var(--primary-color);
padding: var(--spacing);
}

13. Modern CSS Features​

CSS:
/* Custom properties */
:root {
--shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* CSS Filters */
.image {
filter: blur(2px) brightness(120%);
}

/* Blend modes */
.overlay {
background-blend-mode: multiply;
}

🎯 CSS Best Practices​

  1. Use external stylesheets for better maintainability
  2. Organize your CSS with comments and sections
  3. Follow naming conventions (BEM, OOCSS)
  4. Minify CSS for production
  5. Use developer tools for debugging

🚀 Next Steps​

  • Learn CSS preprocessors (Sass, Less)
  • Explore CSS frameworks (Bootstrap, Tailwind)
  • Master CSS architecture patterns

The Complete Web Development Masterclass: HTML, CSS & Beyond​

🌐 Part 1: HTML - The Structure of the Web​

1.1 HTML Fundamentals​

HTML:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
</header>
   
<main>
<article>
<h2>Article Title</h2>
<p>This is paragraph text.</p>
</article>
</main>
   
<footer>
<p>&copy; 2023 My Site</p>
</footer>
</body>
</html>


1.2 Semantic HTML5 Elements​

  • <header>/<footer> - Document header/footer
  • <nav> - Navigation links
  • <main> - Primary content
  • <article> - Independent content
  • <section> - Thematic grouping
  • <aside> - Sidebar content
  • <figure>/<figcaption> - Media with caption

1.3 HTML Forms​

HTML:
<form action="/submit" method="post">
<fieldset>
<legend>User Information</legend>
       
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
       
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
       
<label for="password">Password:</label>
<input type="password" id="password" name="password" minlength="8" required>
       
<button type="submit">Register</button>
</fieldset>
</form>

🎨 Part 2: CSS - Styling the Web​

2.1 CSS Fundamentals​

CSS:
/* Box Model */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: 'Segoe UI', system-ui, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
}

.container {
width: min(90%, 1200px);
margin: 0 auto;
padding: 2rem;
}

2.2 Layout Techniques​

Flexbox:

CSS:
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
gap: 2rem;
}

.card-container {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}

.card {
flex: 1 1 300px;
}


CSS Grid:
CSS:
.grid-layout {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
}

.header {
grid-column: 1 / -1;
}

2.3 Responsive Design​

CSS:
/* Mobile First Approach */
.hero {
padding: 2rem 1rem;
text-align: center;
}

/* Tablet */
@media (min-width: 768px) {
.hero {
padding: 4rem 2rem;
text-align: left;
}
}

/* Desktop */
@media (min-width: 1024px) {
.hero {
display: flex;
align-items: center;
gap: 3rem;
}
}

⚡ Part 3: Modern Web Techniques​

3.1 CSS Variables​

CSS:
:root {
--primary-color: #4361ee;
--secondary-color: #3f37c9;
--text-color: #2b2d42;
--light-gray: #f8f9fa;
--spacing: 1rem;
--border-radius: 8px;
}

.button {
background-color: var(--primary-color);
color: white;
padding: var(--spacing);
border-radius: var(--border-radius);
transition: all 0.3s ease;
}

.button:hover {
background-color: var(--secondary-color);
}

3.2 CSS Animations​

CSS:
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}

.animated-card {
animation: fadeIn 0.6s ease-out forwards;
animation-delay: calc(var(--order) * 0.1s);
}

3.3 Advanced Selectors​

CSS:
/* Attribute selectors */
input[type="text"] {
border: 1px solid #ddd;
}

/* Pseudo-elements */
blockquote::before {
content: open-quote;
font-size: 2em;
}

/* :where() for lower specificity */
:where(article, section) h2 {
margin-bottom: 1em;
}

🔮 Part 4: The Future of CSS​

4.1 Container Queries​

CSS:
.component {
container-type: inline-size;
}

@container (min-width: 400px) {
.component {
display: flex;
gap: 1rem;
}
}

4.2 CSS Nesting​

CSS:
.card {
padding: 1rem;
   
& .title {
font-size: 1.2rem;
}
   
&:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
}

4.3 Viewport Units​

CSS:
.hero {
min-height: 100dvh;
padding: 10dvh 5dvw;
}

Complete CSS Language Reference with Meanings and Usage (English)​

CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of HTML or XML documents. Below is a comprehensive list of CSS properties, their meanings, and usage.


1. CSS Selectors​

Selectors target HTML elements to apply styles.

SelectorMeaningExample Usage
elementSelects HTML elements by tag name.p { color: red; }
.classSelects elements with a specific class..header { font-size: 20px; }
#idSelects an element with a specific ID.#main { width: 100%; }
*Universal selector (selects all elements).* { margin: 0; }
selector1, selector2Groups multiple selectors.h1, h2 { color: blue; }
parent > childDirect child selector.div > p { font-weight: bold; }
ancestor descendantDescendant selector.div p { color: green; }
selector1 + selector2Adjacent sibling selector.h1 + p { margin-top: 0; }
selector1 ~ selector2General sibling selector.h1 ~ p { color: gray; }
[attribute]Selects elements with an attribute.[target] { border: 1px solid; }
:hoverApplies style on mouse hover.a:hover { color: orange; }
:activeApplies style when element is active (clicked).button:active { background: black; }
:focusApplies style when element is focused.input:focus { border-color: blue; }

2. CSS Properties (Commonly Used)​

Text & Font Properties​

PropertyMeaningExample
colorSets text color.color: #FF0000;
font-familyDefines font type.font-family: Arial, sans-serif;
font-sizeSets text size.font-size: 16px;
font-weightSets boldness.font-weight: bold;
text-alignAligns text (left, right, center).text-align: center;
text-decorationAdds underline/overline.text-decoration: underline;
line-heightSets space between lines.line-height: 1.5;

Box Model Properties​

PropertyMeaningExample
width / heightSets element dimensions.width: 300px;
marginSets outer spacing.margin: 10px;
paddingSets inner spacing.padding: 15px;
borderSets border style.border: 1px solid black;
box-sizingDefines sizing behavior.box-sizing: border-box;

Layout & Positioning​

PropertyMeaningExample
displaySets display behavior.display: flex;
positionDefines positioning (static, relative, absolute, fixed).position: relative;
top, right, bottom, leftOffsets positioned elements.top: 20px;
floatAligns elements left/right.float: left;
clearPrevents floating overlap.clear: both;

Flexbox & Grid​

PropertyMeaningExample
flex-directionSets flex container direction.flex-direction: row;
justify-contentAligns flex items horizontally.justify-content: center;
align-itemsAligns flex items vertically.align-items: center;
grid-template-columnsDefines grid columns.grid-template-columns: 1fr 1fr;
gapSets spacing between grid/flex items.gap: 10px;

Background & Colors​

PropertyMeaningExample
background-colorSets background color.background-color: #f0f0f0;
background-imageAdds a background image.background-image: url('bg.jpg');
background-sizeControls image size.background-size: cover;
background-repeatPrevents image repetition.background-repeat: no-repeat;

Transitions & Animations​

PropertyMeaningExample
transitionAdds smooth property changes.transition: all 0.3s ease;
animationApplies keyframe animations.animation: fade 2s infinite;
@keyframesDefines animation steps.@keyframes fade { from { opacity: 0; } }

Responsive Design (Media Queries)​

CSS:
@media (max-width: 768px) {
body { font-size: 14px; }
}

3. CSS Units​

UnitMeaningExample
pxPixels (fixed size).font-size: 16px;
%Percentage (relative to parent).width: 50%;
emRelative to font size.padding: 2em;
remRelative to root font size.margin: 1rem;
vw / vhViewport width/height.width: 100vw;

4. CSS Example (Complete Usage)​



CSS:
/* Selectors & Basic Styling */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

/* Class & ID Styling */
.header {
background: #333;
color: white;
padding: 1rem;
text-align: center;
}

#main-content {
width: 80%;
margin: 2rem auto;
}

/* Flexbox Layout */
.container {
display: flex;
justify-content: space-between;
gap: 20px;
}

/* Hover & Transition Effects */
.button {
background: blue;
color: white;
padding: 10px 20px;
transition: background 0.3s;
}

.button:hover {
background: darkblue;
}

/* Media Query for Responsive Design */
@media (max-width: 600px) {
.container {
flex-direction: column;
}
}

​

CSS controls the visual presentation of web pages. Key concepts include:

  • Selectors (target elements)
  • Properties (define styles)
  • Units (measure sizes)
  • Layout Models (Flexbox, Grid)
  • Responsive Design (Media Queries)

Next Steps in Your Web Dev Journey​

  1. JavaScript Fundamentals
    • DOM Manipulation
    • Event Handling
    • Async Programming
  2. Frontend Frameworks
    • React/Vue/Angular
    • State Management
    • Component Architecture
  3. Backend Development
    • Node.js/Express
    • Databases
    • API Design
  4. Performance Optimization
    • Lazy Loading
    • Code Splitting
    • Caching Strategies
  5. Web Accessibility
    • ARIA Attributes
    • Keyboard Navigation
    • Color Contrast
 

Facebook Comment

Search Google Web Search Google Images Search Google Voice Search Google Videos Search Maps Translate Word
🔍
GE
Google Experiment
Visit Google Experiment
⋮
CS
Code Saya
Visit Code Saya
⋮
SK
Sekolah Koding
Visit Sekolah Koding
⋮
HF
Huggingface
Visit Huggingface
⋮
SL
Sololearn
Visit Sololearn
⋮
LM
Learnx
Visit Learnxinmyminutes
⋮
w3s
W3schools
Visit w3schools
⋮
CW
Codewars
Visit Codewars
⋮
GG
Geeksforgeeks
Visit Geeksforgeeks
⋮
EXC
Exercism
Visit Exercism
⋮
EDX
EDX
Visit EDX
⋮
Add Shortcut
WhatsApp

Customer Service

CS 1

Mr.Ibnu

Loading jadwal...

Hubungi via WhatsApp
CS 2

Mr.Husein

Loading jadwal...

Hubungi via WhatsApp
CS 3

Mr.Hasan

Loading jadwal...

Hubungi via WhatsApp
Top Bottom

Translate Website

Upload Custom Icon

coding Coding
programmer Programmer
webmaster Webmaster
banners.png Banners
Home
What's New Resources Media Gallery
Record your forum activity and save it as MP4
> INITIALIZING ISE CONNECTION...
> BYPASSING SECURITY PROTOCOLS...
> ESTABLISHING WORMHOLE LINK...
> Starting XenForo engine... [DONE]
> Calibrating singularity Hosting parameters... [DONE]
> Establishing Forum Style... [DONE]
> The Programmer Community ready in 3... 2... 1.