Methods to Apply Style: Inline, Document-wide, External

CSS सीधे एक अकेले tag पर लागू किया जा सकता है, पूरे webpage के लिए embed किया जा सकता है, या तुरंत पूरी website style करने के लिए एक central file से link किया जा सकता है।

8 min read · 11 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

अनावश्यक Workload का दुःस्वप्न

कल्पना कीजिए आपने अभी-अभी अपनी campus placements के लिए एक साफ़ three page portfolio website बनाना पूरा किया। आपने इन pages भर दस project headings जोड़ीं, सब एक चमकीले neon blue color में style की गईं। अचानक, आपके professor आपसे कल सुबह से पहले सारी headings का color deep purple में बदलने को कहते हैं। क्या आप हर file खोलते हैं और सारे दस tags एक-एक करके हाथ से update करते हैं? क्या हो अगर आपकी site पचास pages तक बढ़ जाए? आपके designs को एक अकेले cockpit से नियंत्रित करने का एक बेहतर तरीक़ा होना चाहिए।

Theory

Stickies, Note, और Master Blueprint

अपनी website layout को एक multi story student hostel की तरह सोचिए। Inline styling एक छोटे sticky note पर color निर्देश लिखने और इसे सीधे एक कमरे के अंदर एक ख़ास chair पर चिपकाने जैसा है। Document wide styling एक अकेले flat के प्रवेश द्वार पर एक announcement notice board लगाने जैसा है, केवल उस flat के अंदर सब कुछ नियंत्रित करते हुए। External styling warden office के अंदर एक master blueprint document बनाने जैसा है: वहाँ एक line edit कीजिए, और पूरे hostel complex भर हर कमरा तुरंत update होता है।

Theory

Style Application के तीन स्तंभ

CSS3 में, आप तीन अलग approaches इस्तेमाल करके अपने elements पर design rules लागू कर सकते हैं। पहला, inline style एक individual HTML tag के अंदर सीधे style attribute इस्तेमाल करता है। दूसरा, document wide style (जिसे internal CSS भी कहते हैं) एक page के <head> section के भीतर रखे एक <style> element के अंदर rules embed करता है। तीसरा, external style सारे rules एक पूरी तरह अलग .css file में रखता है और इसे <link> tag इस्तेमाल करके आपके HTML documents से जोड़ता है। browser style conflicts को एक सख़्त cascade priority order इस्तेमाल करके हल करता है।

At a glance

CSS styling application methods और उनकी विशेषताओं की तुलना।

MethodSyntax LocationScopeCascade Priority
Inline Styleख़ास HTML tag attribute के अंदरकेवल अकेला elementसबसे ऊँची (बाक़ी को override करती है)
Document-wide<head> में <style> tag के अंदरकेवल अकेला webpageमध्यम
External Style<link> tag के साथ अलग .css fileपूरी websiteसबसे कम

Practical

तीन Application Methods दिखाना

<!DOCTYPE html>
<html>
<head>
  <title>My Portfolio</title>

  <!-- External style: lowest priority, whole site -->
  <link rel="stylesheet" href="styles.css">

  <!-- Document-wide (internal) style: this page only -->
  <style>
    h1 { color: darkblue; }
    p { color: gray; }
  </style>
</head>
<body>
  <h1>Project Showcase</h1>

  <!-- Inline style: highest priority, this element only -->
  <p style="color: red;">This specific text ignores other rules.</p>
</body>
</html>

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Quiz

एक external stylesheet h1 { color: green; } परिभाषित करता है, एक document-wide block h1 { color: blue; } परिभाषित करता है, और एक individual tag <h1 style="color: red;"> लिखा है। browser में heading किस color में render होगी?

  1. Green
  2. Blue
  3. Red
  4. एक style collision conflict के कारण text अदृश्य हो जाएगा
Show the answer

Red

Inline styles की सबसे ऊँची cascade priority है। क्योंकि style attribute सीधे HTML element पर बैठता है, यह document-wide style blocks और external stylesheets दोनों को override करता है, यानी red color जीतता है।

Theory

कदम-दर-कदम Cascade Resolution

आइए ट्रेस करें कि जब styles टकराती हैं एक browser text color कैसे render करता है। मान लीजिए आपकी external CSS file आपके portfolio body text के लिए p { color: black; } कहती है। page two पर, आप चाहते हैं सारे paragraphs gray दिखें, इसलिए आप p { color: gray; } कहता एक document wide block जोड़ते हैं। आख़िर में, एक विशेष alert paragraph के लिए, आप tag में सीधे style="color: red;" लिखते हैं। Step 1: browser external sheet load करता है, text को black set करते हुए। Step 2: document wide rule इसे override करता है, उस page text को gray बनाते हुए। Step 3: inline attribute अंतिम priority लेता है, केवल उस ख़ास alert text को red बनाते हुए।

Think first

Shared Styles Challenge

आपके पास main.css नाम की एक external file है जो आपकी पूरी site के लिए एक dark background set करती है। मन में evaluate कीजिए क्या होता है अगर आप अपने नए contact webpage पर <link> tag शामिल करना भूल जाते हैं, पर fonts के लिए एक internal style block लिखते हैं। tap करने से पहले सोचिए।

Show the answer

contact page अपना dark background layout पूरी तरह खो देगा। चूँकि external file कभी link नहीं की गई, browser के पास वे background rules लाने का कोई तरीक़ा नहीं, यानी page एक default white background के साथ load होगा जबकि केवल local internal font styles बनाए रखेगा।

Watch out

Practical Lab Quick Fix जाल

university lab exams के दौरान, students अक्सर घबराते हैं और हर एक element के लिए inline styles इस्तेमाल करते हैं क्योंकि यह तुरंत results देता है। यह एक गंभीर mark गँवाने वाली ग़लती है। Inline styles CSS के पूरे उद्देश्य को हराते हैं, जो structure को presentation से अलग रखना है। यह गंदा, बेक़ाबू code बनाता है जो भविष्य के modifications को एक जीता-जागता दुःस्वप्न बना देता है। हमेशा external stylesheets को प्राथमिकता दीजिए, और inline styling केवल exceptional, single element overrides के लिए बिल्कुल ज़रूरी होने पर इस्तेमाल कीजिए।

Theory

Industry Standards और भविष्य के Semesters

professional web development और आपके आने वाले Semester 3 projects में, external stylesheets non negotiable हैं। बड़ी companies modular external CSS systems इस्तेमाल करके हज़ारों pages manage करती हैं। अभी link architecture पर महारत हासिल करना पक्का करता है कि आपका code साफ़, scalable, और बाद के semesters में Tailwind या Bootstrap जैसे advanced design frameworks के लिए तैयार रहे।

Summary

Key takeaways

  • Inline styles style attribute इस्तेमाल करके सीधे HTML tags के अंदर declare होते हैं और एक अकेले element को target करते हैं।
  • Document wide styles head element के अंदर रहते हैं और एक पूरे अकेले page layout को नियंत्रित करते हैं।
  • External stylesheets अलग files में रहते हैं और कई webpages भर global design consistency देते हैं।
  • browser style conflicts को cascade priority के अनुसार हल करता है, जहाँ inline styles हमेशा external rules को override करते हैं।
  • Memory Hook: Inline एक अकेली जगह target करता है, internal rules एक अकेला plot, external styles पूरे lot को नियंत्रित करते हैं।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Designing Webpage using CSS-3

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati