CSS Styling: Beyond the Basics
Take your CSS skills further by mastering text styling, the box model, backgrounds, and display properties to create visually appealing websites.
"If Card 1 was an introduction, Card 2 is where we start dressing up. Styling text to look neat and learning to space elements like a pro UI designer."
✍️ Text Styling (So It's Not Flat)
🔤 Text Styling Properties:
Property | Function |
---|---|
color | Text color |
font-size | Font size (px, rem, %, etc) |
font-family | Font type |
font-weight | Font thickness (normal, bold, 500, etc) |
text-align | Alignment (left, right, center, justify) |
line-height | Line spacing |
letter-spacing | Letter spacing |
text-transform | Change case (uppercase/lowercase/capitalize) |
🔧 Example:
CSS
p {
font-family: 'Poppins', sans-serif;
font-size: 18px;
color: #333;
text-align: justify;
line-height: 1.8;
text-transform: capitalize;
}
Your paragraphs won't just be readable, they'll look good too ✨
📦 Box Model: Understanding HTML's Box World
"All HTML elements are essentially... boxes. And CSS helps you arrange these boxes like playing Tetris."
🧱 Box Model consists of:
Box Model
⬅️ Margin: outer space
⬅️ Border: edge line
⬅️ Padding: inner space
⬅️ Content: actual content
🔍 Explanation:
- Content: main content (text/image)
- Padding: space between content & border
- Border: element's edge line
- Margin: space between elements
🔧 Styling Example:
CSS
.box {
width: 300px;
height: 200px;
padding: 20px;
margin: 40px auto;
border: 2px solid #ff4d4d;
background-color: #fff0f5;
}
🧠 Padding = gives content breathing room
🧠 Margin = gives the box space from others
📐 Width & Height
🧊 Important properties:
width
→ element widthheight
→ element height
Units you can use:
px
→ fixed%
→ relative to parentvw
/vh
→ relative to screen size
CSS
.card {
width: 80%;
height: auto;
}
🎨 Background Styling
🌈 Commonly used properties:
Property | Function |
---|---|
background-color | Background color |
background-image | Background image |
background-size | Image size (cover, contain) |
background-repeat | Repeat image or not |
background-position | Image position (center, top, etc) |
CSS
body {
background-color: #f0f0f0;
background-image: url('bg.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
✨ Border & Radius
🔧 Border properties:
CSS
.box {
border: 3px dashed #ff69b4;
border-radius: 12px;
}
border
: edge line (solid, dashed, dotted)border-radius
: makes corners rounded
Perfect for styling cards so they don't look as stiff as a deadline assignment!
🌫️ Box Shadow
Glow effects, neomorphism, or aesthetic shadows can be created with this:
CSS
.card {
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
}
General format:
CSS
box-shadow: x-offset y-offset blur color;
🔎 Block vs Inline vs Inline-block
🧩 Element display types:
Type | Effect |
---|---|
block |
Takes full width (like <div> , <p> ) |
inline |
Only as wide as content (like <span> , <a> ) |
inline-block |
Can set width/height but stays inline |
🔧 Example:
CSS
span {
display: inline-block;
width: 100px;
height: 100px;
}