CSS height और width प्रॉपर्टीज का उपयोग क्रमशः किसी एलिमेंट की ऊंचाई और चौड़ाई निर्दिष्ट करने के लिए किया जाता है। हम max-height, max-width, min-height, और min-width प्रॉपर्टीज का उपयोग करके इन प्रॉपर्टीज के लिए अधिकतम और न्यूनतम मान भी सेट कर सकते हैं।
सिंटैक्स
CSS height और CSS width प्रॉपर्टी का सिंटैक्स निम्नलिखित है:
Selector { height: /*value*/ width: /*value*/ }
एलिमेंट्स की वास्तविक चौड़ाई और ऊंचाई की गणना निम्नानुसार की जाती है:
| बॉक्स साइज | गणना |
|---|---|
| कुल चौड़ाई | width + padding-left + padding-right + border-left + border-right + margin-left + margin-right |
| कुल ऊंचाई | height + padding-top + padding-bottom + border-top + border-bottom + margin-top + margin-bottom |
उदाहरण
निम्नलिखित उदाहरण CSS height और CSS width प्रॉपर्टीज को दर्शाते हैं:
<!DOCTYPE html> <html> <head> <style> #demo { margin: auto; width: 400px; height: 80px; border: 2px solid black; display: flex; border-radius: 15px; } #demo div { flex: 1; border: thin dotted; border-radius: 50%; line-height: 60px; text-align: center; } #orange { box-shadow: inset 0 0 8px orange; } #green { box-shadow: inset 0 0 8px green; } #blue { box-shadow: inset 0 0 8px blue; } #red { box-shadow: inset 0 0 8px red; } </style> </head> <body> <div id="demo"> <div id="orange">Somebody</div> <div id="green">that I</div> <div id="blue">used</div> <div id="red">to know</div> </div> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट देता है:

एक और उदाहरण
<!DOCTYPE html> <html> <head> <style> article { margin: 10% 35%; box-shadow: 0 0 6px 1px black; max-width: 200px; max-height: 150px; overflow: auto; } </style> </head> <body> <h2>Java 8 Features</h2> <article> Lambda expression adds functional processing capability to Java. Referencing functions by their names instead of invoking them directly. Interface to have default method implementation. New compiler tools and utilities are added like 'jdeps' to figure out dependencies. New stream API to facilitate pipeline processing. Improved date time API. Emphasis on best practices to handle null values properly. Nashorn, a Java-based engine to execute JavaScript code. </article> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट देता है:
