CSS Background in hindi
CSS Background का उपयोग webpage में Background Set करने के लिए किया जाता है।
CSS Background को नियत्रित करने के लिए कई अतिरिक्त Background Properties भी Provide कराती है।
जैसे : –
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
- background (shorthand property)
CSS Background Color
जब आप अपने HTML Document के लिए Color Background Set करना चाहते हैं, तो इसके लिए CSS की background-color Property का इस्तेमाल किया जाता है और इसकी Value में Color को Define किया जाता है।
आप Background की color Value को कई तरीकों से define कर सकते हैं। जैसे - color name, Hex, RGB आदि CSS Colors की अधिक जानकारी के लिए आप यहां पर पढ़ सकते हैं।
जैसे : –
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This page has a light blue background color!</p>
</body>
</html>
Output :
CSS Background image
अगर आप webpage के background में image लगाना चाहते हैं तो आप background-image property का उपयोग करके background में image लगा सकते हैं। इसकी value को image URL द्वारा define किया जाता है।
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("paper.gif");
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This page has an image as the background!</p>
</body>
</html>
Output :–
background-repeat
अगर आपकी Image का Size छोटा है। तो वह पूरे Background को Cover नहीं करेगी। इसके लिए background-repeat Property का इस्तेमाल किया जाता है। इसकी चार संभावित Values हो सकती हैं।- repeat
- no-repeat
- repeat-x
- repeat-y
repeat :
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("gradient_bg.png");
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Strange background image...</p>
</body>
</html>
no-repeat :
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("gradient_bg.png");
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Strange background image...</p>
</body>
</html>
repeat-X:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Here, a background image is repeated only horizontally!</p>
</body>
</html>
repeat-Y:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-y;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Here, a background image is repeated only horizontally!</p>
</body>
</html>
CSS Background -Attachment
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
margin-right: 200px;
background-attachment: fixed;
}
</style>
</head>
<body>
<h1>The background-attachment Property</h1>
<p>The background-attachment property specifies whether the background image should scroll or be fixed (will not scroll with the rest of the page).</p>
<p><strong>Tip:</strong> If you do not see any scrollbars, try to resize the browser window.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>
CSS Background Position
CSS Background image default position :
background-image: url("./images/pattern.png");
background-repeat: no-repeat;
CSS Background image center position :
background-image: url("./images/pattern.png");
background-repeat: no-repeat;
background-position: center;
CSS Background image right - bottom position:
background-image: url("./images/pattern.png");
background-repeat: no-repeat;
background-position: bottom right;
CSS Background short hand property
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
<!DOCTYPE html>
<html>
<head>
<style>
body {
background: #ffffff url("img_tree.png") no-repeat right top;
margin-right: 200px;
}
</style>
</head>
<body>
<h1>The background Property</h1>
<p>The background property is a shorthand property for specifying all the background properties in one declaration.</p>
<p>Here, the background image is only shown once, and it is also positioned in the top-right corner.</p>
<p>We have also added a right margin, so that the text will not write over the background image.</p>
</body>
</html>
अगर आपको यह पोस्ट 📑 पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !