I want to make div which take 100% of width and hight of the screen and it may also responsive –
* {
top: 0%;
position: relative;
font-family: 'Imprima', sans-serif;
}
.container {
background-color: #D5C5C6;
display: flex;
flex-direction: column;
align-items: self-start;
gap: 120px;
}
<div class="container">
<div class="nev" id="nevbar"></div>
<div class="hero">
<div class="heading">Beauty Brands</div>
<div class="description">Treat your makeup like jewelry for the face. Play with colors, shapes, structure It can transform you.</div>
<div class="ctc-btn"><a href="">Get Offer</a></div>
</div>
<!-- <div id="brand">Brands</div> -->
<div class="footer">www.logo.com</div>
</div>
2
Answers
Try using
vw
andvh
css units which respond to the size of the screen, they works like the percentage unit.vw
is according to the width of the screen size.Specify 10vw is to take up 10% of the total viewable screen width.
vh
is according to the height of the screen size.Specify 10vh is to take up 10% of the total viewable screen height.
https://www.freecodecamp.org/news/learn-css-units-em-rem-vh-vw-with-code-examples/
height: 100%
means 100% of the parent element’s height.The default height of block-level elements is
fit-content
.fit-content
means, that the height isundefined
but will be calculated to fit the content of the element.If we combine both pieces of information together, you will realize that 100% of undefined is still undefined. As such
100%
only works with a specifically defined height.What you actually want to use are the values
vw
(view width) andvh
(view height) which are units relative to the size of the viewport. The viewport is the visual area of a web browser (not the screen size).However, to work correctly, you need to add a few things to prevent overflow issues.
body { margin: 0; }
.border-box
as otherwise padding or border would also overflow the screen as those are normally calculated on top of the width and height of the element.min-height
or an overflow rule to that element as otherwise a larger content would overflow the element and collide with other content.