मैंने अभी HTML और CSS (और थोड़ा बूटस्ट्रैप) के बारे में सीखना शुरू किया है और मैं एक साधारण स्क्रॉलिंग वेबपेज बनाने की कोशिश कर रहा हूं। मेरी समस्या यह है कि मुझे पृष्ठ की पूरी ऊंचाई को कवर करने के लिए div पृष्ठभूमि छवि नहीं मिल सकती है - यह केवल एच 2 टेक्स्ट तक ही शामिल है, जैसे यह सोचता है कि उस तत्व का अंत पृष्ठ का अंत है। मुझे नहीं पता कि यह ऐसा क्यों कर रहा है और मैं इसे ठीक नहीं कर पाया। यह वास्तव में मुझे स्टम्प्ड कर दिया है और मुझे यकीन है कि इसका वास्तव में एक आसान समाधान है जिसे मैंने याद किया है। किसी भी सलाह की अत्यधिक सराहना की जाएगी।
यह रहा codepen:
body {
background-color: rgb(255, 255, 255);
}
#front {
background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
overflow: hidden;
background-size: cover;
width: 100%;
height: 100%;
}
#h1 {
color: white;
font-size: 50px;
margin-top: 40vh;
padding: 10px;
background: rgba(43, 142, 255, 0.4);
}
#pt {
color: white;
font-size: 30px;
background: rgba(39, 220, 130, 0.4);
}
<ul style="z-index:9;">
<li>
<a class="active" href="#"><img class="img-fluid" style="width:auto;height:auto;max-height:26px;max-width:20px;" src="https://image.ibb.co/mg1s3a/lyreimage27.png" alt="website icon"></img> placeholder inc.</a>
</li>
<li><a href="#">About
</a>
</li>
<li><a style="text-decoration:none" href="#">Portfolio</a>
</li>
<li><a href="#">Contact</a>
</li>
</ul>
<header>
<div id="front">
<div class="container-fluid">
<h1 id="h1" class="text-center">Placeholder</h1>
<h2 id="pt" class="text-center">Placeholder Text</h2>
</header>
4 जवाब
मैंने आपके मार्कअप को थोड़ा सा साफ़ कर दिया है (जब संभव हो तो इनलाइन शैलियों का उपयोग न करने का प्रयास करें) और मुझे लगता है कि मैंने वह प्रभाव प्राप्त किया जो आप ढूंढ रहे हैं।
#front {
background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
overflow: hidden;
background-size: cover;
width: 100%;
min-height: 100vh;
}
.text-center {
text-align: center;
}
h1 {
color: white;
font-size: 50px;
margin-top: 40vh;
padding: 10px;
background: rgba(43, 142, 255, 0.4);
}
h2 {
color: white;
font-size: 30px;
background: rgba(39, 220, 130, 0.4);
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.7);
position: fixed;
top: 0;
width: 100%;
font-size: 16px;
z-index: 9;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
color: white;
background-color: rgba(39, 220, 130, 0.4);
transition: 0.5s;
text-decoration: none;
}
.active {
color: white;
background-color: rgba(43, 142, 255, 0.4);
}
.active:hover {
color: white;
text-decoration: none;
}
.active img {
width:auto;
height:auto;
max-height:26px;
max-width:20px;
}
<ul>
<li><a class="active" href="#"><img class="img-fluid" src="https://image.ibb.co/mg1s3a/lyreimage27.png" alt="website icon" />placeholder inc.</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a>
</li>
</ul>
<header id="front">
<div>
<div class="container-fluid text-center">
<h1>Placeholder</h1>
<h2>Placeholder Text</h2>
</div>
</div>
</header>
#front
, header
के आकार का 100% है। अपने शीर्षलेख को height: 100%
पर सेट करने का प्रयास करें। वैकल्पिक रूप से (बेहतर समाधान), यदि आप चाहते हैं कि यह पूरे पृष्ठ को कवर करे, तो पृष्ठभूमि को शरीर पर सेट करें। यह आसान विकल्प है और अधिक समझ में आता है।
अपने हेडर तत्व की ऊंचाई 100vh पर सेट करें;
तो अपने सीएसएस में जोड़ें:
header {
height: 100vh;
}
आपके #front
div में पूरे पृष्ठ पर प्रदर्शित करने के लिए पर्याप्त सामग्री नहीं है। माना जाता है कि आपके पास पूरे पृष्ठ को कवर करने के लिए पर्याप्त सामग्री है या फिर background-image
को body
तत्व के लिए सेट करें। अन्यथा नीचे दिए अनुसार अपना #front
css बदलें।
#front {
background: url("https://image.ibb.co/mjTmwv/port34.png") no-repeat;
overflow: hidden;
background-size: cover;
width: 100%;
height: 100vh;
}