๐งฑ CSS COURSE โ MODULE 6: DISPLAY & VISIBILITY
๐ File: display.md
๐งฑ Display & Visibility in CSS
๐ Introduction
The display property controls how an element behaves in layout.
๐ It decides:
- if an element takes full width
- if it sits inline
- if it is hidden
- how it flows on the page
๐ง 1. Block Elements
div {
display: block;
}
๐ Behavior:
- Takes full width
- Starts on new line
Examples:
<div><h1><p>
๐ 2. Inline Elements
span {
display: inline;
}
๐ Behavior:
- Takes only needed width
- Stays in same line
Examples:
<span><a>
๐งฉ 3. Inline-Block
button {
display: inline-block;
}
๐ Behavior:
- Stays inline
- Can set width/height
โ Best of both worlds
๐ซ 4. None (Hide Element)
div {
display: none;
}
๐ Behavior:
- Element disappears completely
- Takes no space
๐๏ธ 5. Visibility Property
div {
visibility: hidden;
}
๐ Behavior:
- Element is invisible
- BUT still takes space
๐ง Display vs Visibility
| Property | Visible | Space |
|---|---|---|
| display: none | โ | โ |
| visibility: hidden | โ | โ |
๐งฉ Real Example
<div class="box">Block Element</div>
<span class="text">Inline Element</span>
<button>Button</button>
.box {
display: block;
background: lightblue;
}
.text {
display: inline;
color: red;
}
button {
display: inline-block;
padding: 10px;
}
๐ง Important Concept
Display = how element behaves in layout
โ ๏ธ Common Mistakes
- Using block when inline is needed โ
- Using inline when width is needed โ
- Confusing visibility vs display โ
- Breaking layout with display changes โ
๐ฏ Pro Tip
๐ Most modern UI uses:
blockโ layout sectionsinline-blockโ buttonsflexโ advanced layout (next module)
๐งช Mini Exercise
Create a page with:
- A block element (div)
- Inline text (span)
- Inline-block button
- One hidden element using
display:none - One element using
visibility:hidden