CSS Image Shapes
In this page:
img {
shape-outside: circle();
float: left;
border-radius: 50%;
}
border-radius से Circles और Ellipses
किसी square image पर border-radius: 50% set करना उसे एक perfect circle में crop कर देता है, जबकि किसी non-square image पर इसे लागू करने से इसके बजाय एक ellipse बनता है — यह सबसे simple shape technique है और बिना किसी vendor prefixes के हर modern browser में काम करती है।
- Accepted values:
- border-radius: 50% — square box पर circle, वरना ellipse
- border-radius: <length> — fixed rounding
- border-radius: A / B — horizontal / vertical radii
- aspect-ratio: 1 — box को square रखता है
उदाहरण: Circles and Ellipses with border-radius
<style>
img {
border-radius: 50%;
}
</style>
<img src="https://placehold.co/100x100" alt="Cropped into a circle">
clip-path का परिचय
clip-path circle(), ellipse(), polygon(), या inset() जैसे basic shape functions इस्तेमाल करके किसी element के लिए एक arbitrary visible region define करता है — defined shape के बाहर की कोई भी चीज़ बस clip हो जाती है, नीचे page background (या इसके पीछे जो कुछ भी है) को reveal करते हुए।
- Accepted values:
- clip-path: circle() — circular clip
- clip-path: ellipse() — elliptical clip
- clip-path: polygon() — कोई भी straight-edged shape
- clip-path: inset() — rectangle, optionally rounded
- clip-path: path() — एक SVG path string के साथ clip
- clip-path: none — default, कोई clipping नहीं
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: Introducing clip-path
<style>
img {
clip-path: circle(50%);
}
</style>
<img src="https://placehold.co/150x150" alt="Clipped, revealing what's behind it">
Polygon Shapes
clip-path: polygon(...) x,y coordinate pairs की एक list लेता है जो listed points को element के box के चारों ओर order में जोड़कर एक custom straight-edged shape — एक triangle, एक diamond, एक hexagon, या एक arrow — define करती है।
- Accepted values:
- polygon(x y, x y, ...) — vertices की list, कम से कम तीन
- polygon(evenodd, ...) — fill rule (default nonzero है)
- <percentage> — reference box के relative
- <length> — fixed offset
उदाहरण: Polygon Shapes
<style>
.triangle {
width: 150px;
height: 150px;
background: teal;
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
</style>
<div class="triangle"></div>
Shape Changes को Animate करना
क्योंकि clip-path values को transition किया जा सकता है, किसी element को hover करना उसकी clipped shape को एक polygon से दूसरे में smoothly morph कर सकता है (जब तक दोनों shapes में coordinate points की संख्या बराबर हो), एक technique जो सिर्फ border-radius से संभव नहीं है।
- Accepted values:
- clip-path: polygon(...) — जब point count match करे तो animatable
- transition: clip-path 0.4s — change animate करता है
- समान संख्या में points — smooth interpolation के लिए ज़रूरी
- clip-path: none — interpolate नहीं किया जा सकता
उदाहरण: Animating Shape Changes
<style>
.shape {
width: 150px;
height: 150px;
background: crimson;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
transition: clip-path 0.3s;
}
.shape:hover {
clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
</style>
<div class="shape"></div>
border-radius बनाम clip-path
border-radius सिर्फ corners को round करता है और rectangles-with-rounded-corners, circles, और ellipses के अलावा कुछ produce नहीं कर सकता, जबकि clip-path arbitrary polygon और curve-based shapes बना सकता है — जब भी desired shape कोई simple rounded rectangle या ellipse न हो तो clip-path इस्तेमाल करें।
उदाहरण: border-radius vs clip-path
<style>
.rounded {
width: 100px;
height: 100px;
background: gray;
border-radius: 20px;
}
.hexagon {
width: 100px;
height: 100px;
background: gray;
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
</style>
<div class="rounded"></div>
<div class="hexagon"></div>
clip-pathइस्तेमाल करना और उम्मीद करना कि layout space बदलेगा, जबकि यह वही रहती है।- गलत order में points के साथ एक
polygon()लिखना, इसलिए shape गलत दिखती है। - किसी rectangle पर
border-radius: 50%इस्तेमाल करना और एक oval मिलना, जबकि circle के लिए एक square चाहिए।
हर modern browser में supported: Chrome, Firefox, Safari, Edge और Opera।
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Gradients
- CSS Shadows
- CSS Filters
- CSS Blend Modes
- CSS Transforms
- CSS 2D Transforms
- CSS 3D Transforms
- CSS Transitions
- CSS Animations
- CSS Image Styling
- CSS Image Effects
- CSS Hover Overlays
- CSS Image Modal
- CSS Image Centering
- CSS Image Shapes
- CSS Buttons
- CSS Columns
- CSS Clip Path
- CSS Shapes
- CSS Scroll Snap
- CSS Architecture: BEM
- CSS Custom Properties