CSS - Cascading Style Sheets
Master the art of styling your web pages
🎨 What is CSS?
CSS (Cascading Style Sheets) is the language that describes how HTML elements should be displayed on screen, paper or other media. It controls the layout, colors, fonts and visual effects of a web page.
Without CSS
Simple Title
Normal text without style.
With CSS
Elegant Title
Text with an attractive style.
📝 Syntax of CSS
Selects the HTML elements the styles will be applied to
The feature you want to change (color, size, margin, etc.)
The specific value for the property (blue, 32px, center, etc.)
🎯 CSS Selectors
Selectors by Element
Selects elements by their tag HTML
p { color: red; }
Selectors by Class
Selects elements with a specific class
.destacado { background: yellow; }
Selectors by ID
Selects a unique element by its ID
#header { height: 100px; }
Selectors by Attribute
Selects elements with a specific attribute
input[type="text"] { border: 1px solid; }
Pseudo-clases
Selects elements in a specific state
a:hover { color: blue; }
Combinators
Combines selectors for greater specificity
div > p { margin: 0; }
HTML Example:
<div id="container">
<h1 class="titulo">Title</h1>
<p class="destacado">Highlighted paragraph</p>
<p>Normal paragraph</p>
<a href="#">Link</a>
<input type="text" placeholder="Type something">
</div>
Result:
✨ Main Properties
This text will change based on the selected properties. Try it!
p {
color: #3498db;
font-size: 16px;
font-weight: normal;
}
Background demo area
📱 Responsive Design
Media Queries:
/* Mobile First */
.container {
width: 100%;
}
/* Tablet */
@media (min-width: 768px) {
.container {
width: 750px;
}
}
/* Desktop */
@media (min-width: 1024px) {
.container {
width: 970px;
}
}
🎭 Animations and Transitions
/* Animación de rebote */
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-30px); }
}
.elemento {
animation: bounce 1s infinite;
}
🔧 Application Methods
CSS External
.css Separate file linked in the HTML
<link rel="stylesheet" href="estilos.css">
✅ Advantages:
- Reusable
- Maintainable
- Cacheable
CSS Internal
Styles inside the <style> tag in the HTML
<style> p { color: red; } </style>
✅ Advantages:
- Quick to implement
- Useful for single pages
CSS Inline
Styles directly on elements with the style
<p style="color: blue;">Texto</p>
✅ Advantages:
- High specificity
- Useful for dynamic styles
🛠️ Tools and Resources
🖌️ Preprocessors
- SASS/SCSS: Variables, mixins, nesting
- Less: Similar to SASS with different syntax
- Stylus: Flexible syntax and powerful
📚 Frameworks CSS
- Bootstrap: Most popular framework
- Tailwind CSS: CSS utility-first
- Bulma: Modern and based on Flexbox
🔍 Development Tools
- Browser DevTools: Inspect and modify CSS
- CSS Grid Generator: Visual tools for Grid
- Flexbox Froggy: Game to learn Flexbox
💪 Practice Area
CSS Editor:
Result:
💡 Tips for Mastering CSS
Mobile First
Start designing for mobile and then scale up for larger screens
CSS Variables
Use variables (custom properties) to keep things consistent
Specificity
Avoid !important and understand how the cascade works
Performance
Minimize CSS and use properties that don't cause repaint