Making div background same height as body

Making div background same height as body



i have been trying to solve this for like 2 hours now.. tried multiple guides, nothing worked.



Here is my css:


body
margin:0;
background:url('chalk.jpeg');


html, body
height: 100%;


.welcome
text-align: center;
position:relative;
height:100%;
background:rgba(38, 36, 15, 0.7);



However, for some reason, the page looks like this: https://i.imgur.com/iPvMTk1.jpg



I want the welcome div background to be on top of the body background image until the end of the page. Tried many solutions but nothing would work.






Basically I want to stretch the welcome div background to the bottom of the page. Nothing is under it.

– Desii
Dec 9 '17 at 11:32






The background of the welcome div has a 0.7 opacity, so the body image will still be visible

– Desii
Dec 9 '17 at 11:33




1 Answer
1



You can do it with viewport units where the body element takes 100% of the viewport height with the height: 100vh, then just stretch the .welcome div with height: 100%:


body


100%


height: 100vh


.welcome


height: 100%




html, body
width: 100%;
height: 100vh; /* 100% of the viewport height */
margin: 0;


body
background: url('http://placehold.it/1600x900') no-repeat center center; /* modified */
background-size: cover; /* recommended / also try the "contain" */


.welcome
text-align: center;
position: relative;
height: 100%;
background: rgba(38, 36, 15, 0.7);


<div class="welcome">welcome div</div>



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế