Skip to content

Commit 35d67e8

Browse files
Merge pull request #92 from devajuw/html-block
Added HTML block and Inline Section and content inside
2 parents caa8d76 + 505b477 commit 35d67e8

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
id: html-block
3+
sidebar_position: 6
4+
title: Html Block and Inline Elements
5+
sidebar_label: Html Block and Inline Elements
6+
---
7+
8+
# HTML Block and Inline Elements
9+
10+
## 🎯 Quick Overview
11+
12+
**Block Elements** = Full width, new line
13+
**Inline Elements** = Content width, same line
14+
15+
---
16+
17+
## 📋 Block Elements
18+
19+
Block elements always start on a new line and take full width.
20+
21+
### Common Block Elements
22+
23+
| Element | Purpose |
24+
|---------|---------|
25+
| `<div>` | Container |
26+
| `<h1>-<h6>` | Headings |
27+
| `<p>` | Paragraphs |
28+
| `<ul>`, `<ol>` | Lists |
29+
| `<li>` | List items |
30+
| `<section>` | Content sections |
31+
| `<article>` | Independent content |
32+
| `<header>`, `<footer>` | Page structure |
33+
| `<nav>` | Navigation |
34+
35+
### Example
36+
```html
37+
<div>This is a container</div>
38+
<p>This is a paragraph</p>
39+
<h1>This is a heading</h1>
40+
```
41+
42+
**Browser Output:**
43+
```
44+
┌─────────────────────────────────────────┐
45+
│ This is a container │
46+
└─────────────────────────────────────────┘
47+
48+
┌─────────────────────────────────────────┐
49+
│ This is a paragraph │
50+
└─────────────────────────────────────────┘
51+
52+
┌─────────────────────────────────────────┐
53+
│ THIS IS A HEADING (large & bold) │
54+
└─────────────────────────────────────────┘
55+
```
56+
57+
---
58+
59+
## 🔗 Inline Elements
60+
61+
Inline elements flow with text and take only needed space.
62+
63+
### Common Inline Elements
64+
65+
| Element | Purpose |
66+
|---------|---------|
67+
| `<span>` | Generic inline container |
68+
| `<a>` | Links |
69+
| `<strong>` | **Bold** text |
70+
| `<em>` | *Italic* text |
71+
| `<img>` | Images |
72+
| `<code>` | Code snippets |
73+
| `<br>` | Line break |
74+
| `<input>` | Form inputs |
75+
| `<button>` | Buttons |
76+
77+
### Example
78+
```html
79+
<p>This is <strong>bold</strong> and <em>italic</em> text with a <a href="#">link</a>.</p>
80+
```
81+
82+
**Browser Output:**
83+
```
84+
This is bold and italic text with a link.
85+
↑ ↑ ↑
86+
bold italic blue link
87+
```
88+
89+
---
90+
91+
## 🔄 Visual Comparison
92+
93+
### Block Behavior
94+
```html
95+
<h1>Title</h1>
96+
<p>Paragraph text here</p>
97+
<div>Container content</div>
98+
```
99+
100+
**Browser Output:**
101+
```
102+
┌─────────────────────────────────────────┐
103+
│ TITLE (very large & bold) │
104+
└─────────────────────────────────────────┘
105+
106+
┌─────────────────────────────────────────┐
107+
│ Paragraph text here │
108+
└─────────────────────────────────────────┘
109+
110+
┌─────────────────────────────────────────┐
111+
│ Container content │
112+
└─────────────────────────────────────────┘
113+
```
114+
115+
### Inline Behavior
116+
```html
117+
<span>Text</span><strong>Bold</strong><em>Italic</em><a href="#">Link</a>
118+
```
119+
120+
**Browser Output:**
121+
```
122+
TextBoldItalicLink (all on one line)
123+
↑ ↑ ↑
124+
bold italic blue
125+
```
126+
127+
### Mixed Example
128+
```html
129+
<div>
130+
Block container with <strong>bold</strong> and <em>italic</em> inline text.
131+
</div>
132+
<p>Another paragraph with a <a href="#">clickable link</a>.</p>
133+
```
134+
135+
**Browser Output:**
136+
```
137+
┌─────────────────────────────────────────┐
138+
│ Block container with bold and italic │
139+
│ inline text. │
140+
└─────────────────────────────────────────┘
141+
142+
┌─────────────────────────────────────────┐
143+
│ Another paragraph with a clickable link │
144+
└─────────────────────────────────────────┘
145+
```
146+
147+
---
148+
149+
## 🎛️ CSS Display Control
150+
151+
```css
152+
/* Change behavior */
153+
span { display: block; } /* Inline → Block */
154+
div { display: inline; } /* Block → Inline */
155+
img { display: inline-block; } /* Hybrid */
156+
```
157+
158+
### Display Values
159+
- **`block`** - Full width, new line
160+
- **`inline`** - Content width, same line
161+
- **`inline-block`** - Content width but can set width/height
162+
- **`none`** - Hide element
163+
164+
---
165+
166+
## 📏 Quick Reference
167+
168+
| Type | Width | New Line | Can Contain | Margins/Padding |
169+
|------|-------|----------|-------------|-----------------|
170+
| **Block** | Full | ✅ Yes | Block + Inline | All sides |
171+
| **Inline** | Content | ❌ No | Inline only | Left/Right only |
172+
173+
---
174+
175+
## 🚫 Nesting Rules
176+
177+
### ✅ Allowed
178+
```html
179+
<div>
180+
<p>Text with <strong>bold</strong> word</p>
181+
</div>
182+
```
183+
184+
**Browser Output:**
185+
```
186+
┌─────────────────────────────────────────┐
187+
│ Text with bold word │
188+
└─────────────────────────────────────────┘
189+
```
190+
191+
### ❌ Not Allowed
192+
```html
193+
<strong>
194+
<div>Block inside inline</div> <!-- Wrong! -->
195+
</strong>
196+
```
197+
198+
---
199+
200+
## ✨ Key Takeaways
201+
202+
- **Block** = structure and layout
203+
- **Inline** = text formatting
204+
- Block elements stack vertically
205+
- Inline elements flow horizontally
206+
- Use CSS `display` to change behavior
207+
208+

0 commit comments

Comments
 (0)