CSS Logical Properties
In this page:
selector {
margin-inline: length;
padding-block: length;
border-inline-start: width style color;
}
Logical बनाम Physical Properties
Physical properties (जैसे margin-left) सीधे physical screen boundaries से बंधी होती हैं। Logical properties (जैसे margin-inline-start) relative होती हैं, webpage की text direction और writing mode के आधार पर automatically adapt होते हुए।
- international languages को natively support करने वाले flexible layouts बनाने के लिए physical properties के बजाय logical properties इस्तेमाल करें।
- Accepted values:
- margin-inline-start — LTR में margin-left को replace करता है
- margin-block-end — margin-bottom को replace करता है
- padding-inline — left और right padding को replace करता है
- inset-block-start — top को replace करता है
- width / height — inline-size / block-size बन जाते हैं
उदाहरण: Logical vs. Physical Properties
<style>
.physical {
margin-left: 20px;
background: lightblue;
padding: 8px;
margin-bottom: 8px;
}
.logical {
margin-inline-start: 20px;
background: lightgreen;
padding: 8px;
}
</style>
<div class="physical">Always left, regardless of direction</div>
<div class="logical" dir="rtl">Adapts: becomes right in RTL</div>
Block और Inline Axes को समझना
Logical properties दो main axes इस्तेमाल करती हैं: block axis (default रूप से vertical coordinates) और inline axis (default रूप से horizontal coordinates)। Start और end values define करते हैं कि content इन axes के साथ कहाँ शुरू और खत्म होता है।
- block को paragraphs stack होने की direction (vertical) की तरह सोचें, और inline को words चलने की direction (horizontal) की तरह।
- Accepted values:
- inline axis — जिस direction में text flow होता है
- block axis — जिस direction में blocks stack होते हैं
- writing-mode: horizontal-tb — inline horizontal है, block vertical है
- writing-mode: vertical-rl — inline vertical है, block right से left जाता है
उदाहरण: Understanding Block and Inline Axes
<style>
.box {
padding-block-start: 10px;
padding-inline-start: 20px;
background: lightblue;
border: 1px solid #99a;
}
</style>
<div class="box">Block = vertical stacking axis, inline = horizontal reading axis</div>
Logical Padding और Margin Shorthands
आप shorthand properties इस्तेमाल करके logical padding और margins declare कर सकते हैं: margin-inline (left और right margins के लिए) और padding-block (top और bottom padding के लिए), अपनी stylesheets को साफ़ और पढ़ने में आसान रखते हुए।
- vertical padding set करने के लिए padding-block, और अपने buttons पर horizontal padding set करने के लिए padding-inline इस्तेमाल करें।
- Accepted values:
- margin-block: <length> — block axis पर start और end
- margin-inline: <length> — inline axis पर start और end
- padding-block | padding-inline — padding के लिए वही
- margin-inline: auto — horizontally center करता है
उदाहरण: Logical Padding and Margin Shorthands
<style>
.box {
margin-inline: 20px;
padding-block: 10px;
background: lightblue;
border: 1px solid #99a;
}
</style>
<div class="box">margin-inline sets left+right, padding-block sets top+bottom</div>
Logical Borders
Logical border properties आपको अपनी text direction के आधार पर borders को dynamically style करने देती हैं। border-block-start (default रूप से top border) और border-inline-start (default रूप से left border) जैसी properties आपके layouts को readable रखने के लिए automatically adapt होती हैं।
- अपने alerts और quotes पर vertical accent lines को साफ़ तरीके से style करने के लिए border-inline-start इस्तेमाल करें।
- Accepted values:
- border-inline: <width> <style> <color> — दोनों inline sides
- border-block-start: <...> — एक side
- border-start-start-radius: <length> — logical corner radius
- border-inline-end-width: <length> — single logical side
उदाहरण: Logical Borders
<style>
.alert {
border-inline-start: 4px solid red;
}
</style>
<div class="alert">Accent border adapts to reading direction</div>
Logical Dimensions (block-size और inline-size)
Logical dimensions physical width और height properties को replace करती हैं। inline-size property horizontal dimension (default रूप से width) control करती है, और block-size property vertical dimension (default रूप से height) control करती है।
- vertical reading modes को support करने वाले responsive layouts design करते समय width के बजाय inline-size इस्तेमाल करें।
- Accepted values:
- inline-size: <length> — horizontal writing modes में width को replace करता है
- block-size: <length> — horizontal writing modes में height को replace करता है
- min-inline-size | max-inline-size — logical min/max width
- min-block-size | max-block-size — logical min/max height
उदाहरण: Logical Dimensions (block-size & inline-size)
<style>
.box {
inline-size: 200px;
block-size: 100px;
background: lightblue;
border: 1px solid #99a;
}
</style>
<div class="box">inline-size = width, block-size = height, by default</div>
- एक ही element पर physical margins और logical padding को mix करना, layout conflicts पैदा करते हुए।
- यह भूल जाना कि block-size और inline-size relative हैं और अगर आप webpage की writing mode बदलें तो rotate हो सकते हैं।
- non-standard logical property keys इस्तेमाल करना जिन्हें browsers parse करने में fail हो जाते हैं।
- Logical properties relative directions हैं जो webpage की reading direction के आधार पर automatically adapt होती हैं।
- Block coordinates vertical stacking flow handle करते हैं, जबकि inline coordinates horizontal text flow handle करते हैं।
- साफ़, international websites बनाने के लिए physical properties को logical properties (जैसे margin-inline, padding-block, और inline-size) से replace करें।
Standard CSS logical properties और axis directions हर modern web browser द्वारा natively supported हैं।
Chapter Quiz — Complete all 25 topics to unlock
0/25 topics done
Complete these topics first:
- CSS Container Queries
- CSS Subgrid
- CSS Logical Properties
- CSS Logical Sizing
- CSS Writing Modes
- CSS Aspect Ratio
- CSS Object Fit
- CSS object-position
- CSS Masking
- CSS Math Functions
- CSS Motion Path
- CSS @supports
- CSS @property
- CSS At-Rules
- CSS Cursor
- CSS Will Change
- CSS User Interface
- CSS Print Styles
- CSS Pagination (Print)
- CSS Dark Mode
- CSS Accessibility
- CSS Performance
- CSS Preprocessors
- CSS Frameworks Overview
- CSS Interview Prep