CSS Website Layout
In this page:
header, nav, main, footer {
display: block;
}
.container {
display: grid | flex;
}
Semantic Page Outline
एक professional website एक semantic HTML structure से शुरू होती है। semantic layout tags (जैसे header, footer, main, और nav) इस्तेमाल करना search engines और assistive devices के लिए साफ़ page zones define करता है।
उदाहरण: The Semantic Page Outline
<style>
header, nav, main, footer {
padding: 12px;
color: white;
}
header { background: steelblue; }
nav { background: seagreen; }
main { background: #555; }
footer { background: #333; }
</style>
<header>Site Header</header>
<nav>Navigation</nav>
<main>
<p>Main content</p>
</main>
<footer>Site Footer</footer>
Two-Column Flexbox Layouts
अपने main content area और एक sidebar column को साथ-साथ arrange करने के लिए, आप एक flexible Flexbox container इस्तेमाल कर सकते हैं। यह sidebar को एक fixed width बनाए रखने देता है जबकि content area बची हुई screen space भरने के लिए expand होता है।
उदाहरण: Two-Column Flexbox Layouts
<style>
.layout {
display: flex;
}
.sidebar {
width: 200px;
background: steelblue;
color: white;
padding: 10px;
}
.content {
flex: 1;
background: #eef;
padding: 10px;
}
</style>
<div class="layout">
<div class="sidebar">Sidebar</div>
<div class="content">Main content area</div>
</div>
Responsive Grid Cards
tools या content cards की lists को साफ़ तरीके से दिखाने के लिए, आप एक responsive CSS Grid इस्तेमाल कर सकते हैं। auto-fit और minmax() functions इस्तेमाल करके, आप self-responsive grids बना सकते हैं जो screen sizes छोटे होने पर automatically cards को नई lines में wrap कर देते हैं।
उदाहरण: Responsive Grid Cards
<style>
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
}
.cards div {
background: mediumseagreen;
color: white;
padding: 16px;
}
</style>
<div class="cards">
<div>Card</div>
<div>Card</div>
<div>Card</div>
</div>
Persistent Header App Frames
अपने web applications को native mobile apps जैसा महसूस कराने के लिए, आप अपने header bar को screen के top पर और अपने footer navigation menu को bottom पर lock करने के लिए fixed positioning इस्तेमाल कर सकते हैं, users के scroll करते समय उन्हें visible रखते हुए।
उदाहरण: Persistent Header App Frames
<style>
header {
position: fixed;
top: 0;
width: 100%;
background: steelblue;
color: white;
padding: 10px;
text-align: center;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
background: #333;
color: white;
padding: 10px;
text-align: center;
}
body {
padding-top: 50px;
padding-bottom: 50px;
}
.content p {
background: #f0f0f0;
padding: 12px;
margin: 10px 0;
}
</style>
<header>Fixed Header</header>
<div class="content">
<p>Scroll to see the header and footer stay fixed. Paragraph 1.</p>
<p>Paragraph 2.</p>
<p>Paragraph 3.</p>
<p>Paragraph 4.</p>
<p>Paragraph 5.</p>
<p>Paragraph 6.</p>
<p>Paragraph 7.</p>
<p>Paragraph 8.</p>
</div>
<footer>Fixed Footer</footer>
Responsive Media Query Reflows
यह सुनिश्चित करने के लिए कि आपकी website layout responsive है, CSS media queries इस्तेमाल करें ताकि छोटे mobile displays पर देखे जाने पर elements automatically adapt और stack हों, side-by-side columns को single vertical columns में बदलते हुए।
उदाहरण: Responsive Media Query Reflows
<style>
.columns {
display: flex;
gap: 8px;
}
@media (max-width: 600px) {
.columns {
flex-direction: column;
}
}
.columns div {
background: steelblue;
color: white;
padding: 10px;
flex: 1;
}
</style>
<div class="columns">
<div>Column A</div>
<div>Column B</div>
</div>
- semantic layout tags इस्तेमाल करने के बजाय global styling के लिए standard HTML element tags इस्तेमाल करना।
- fixed top navigation bar इस्तेमाल करते समय body container में top padding जोड़ना भूल जाना, जिससे content cutoff होता है।
- positive tabindex values (जैसे tabindex="1") इस्तेमाल करना, जो logical tab navigation flow को बिगाड़ देता है।
- Semantic HTML tags (जैसे header, footer, और nav) आपके webpage पर layout landmarks की तरह काम करते हैं।
- Flexbox इस्तेमाल करके sidebars और content containers को साफ़ तरीके से साथ-साथ align करें, और responsive CSS Grids इस्तेमाल करके cards को group करें।
- छोटे mobile displays पर elements को adapt और stack करने के लिए CSS media queries इस्तेमाल करके layouts को responsive रखें।
Standard webpage layout tags, Flexbox displays, और CSS Grid systems हर modern web browser द्वारा natively supported हैं।
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: