हम सीएसएस अधिकतम-चौड़ाई संपत्ति का उपयोग करके किसी तत्व के सामग्री बॉक्स के लिए एक निश्चित अधिकतम-चौड़ाई परिभाषित कर सकते हैं जो तत्व के सामग्री बॉक्स को चौड़ा नहीं होने देता, भले ही चौड़ाई अधिकतम-चौड़ाई से अधिक हो।
सिंटैक्स
CSS अधिकतम-चौड़ाई गुण का सिंटैक्स इस प्रकार है -
Selector {
max-width: /*value*/
} आइए CSS अधिकतम-चौड़ाई गुण के लिए एक उदाहरण देखें -
उदाहरण
<!DOCTYPE html>
<html>
<head>
<title>CSS max-width Property</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(135deg, #dc3545 0%, #9599E2 100%);
text-align: center;
border-radius: 10px;
}
#contentDiv{
max-width:200px;
overflow: hidden;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv">
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
</div>
<button onclick="add()" class="btn">Set maxWidth</button>
</div>
<script>
function add() {
document.querySelector('#contentDiv').style.maxWidth = "100%";
}
</script>
</body>
</html> आउटपुट
‘मैक्सविड्थ सेट करें’ clicking क्लिक करने से पहले बटन -

‘मैक्सविड्थ सेट करें’ clicking क्लिक करने के बाद बटन -

आइए CSS की अधिकतम-चौड़ाई वाली संपत्ति के लिए एक और उदाहरण देखें -
उदाहरण
<!DOCTYPE html>
<html>
<head>
<title>CSS max-width Property</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(135deg, #dc3545 0%, #9599E2 100%);
text-align: center;
border-radius: 10px;
}
#contentDiv1, #contentDiv2{
width:100%;
border: 1px solid black;
margin: 0 auto;
}
#contentDiv2{
width: 80%;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv1">
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
</div>
<div id="contentDiv2">
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy.
</div>
<button onclick="add()" class="btn">Set maxWidth</button>
</div>
<script>
function add() {
document.querySelector('#contentDiv1').style.maxWidth = "80%";
}
</script></body></html> आउटपुट
‘मैक्सविड्थ सेट करें’ clicking क्लिक करने से पहले बटन -

‘मैक्सविड्थ सेट करें’ clicking क्लिक करने के बाद बटन -
