I have problems not being able to make a container display a height of 100% and a width of 50% on tmy screen despite my CSS already mentioning those specified measurements in the appropriate div class. I want it to look like my design in the first image below but i got the second image below that as my result.
enter image description here
My result is the one below
enter image description here
This is my current HTML code
<!doctype html>
<html>
<head>
<link href="file:///C:/xampp/htdocs/templatemo_591_villa_agency/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="ID-registration">
<div class="application-image-2">
<img id="passport-image"
src="file:///C:/xampp/htdocs/templatemo_591_villa_agency/assets/images/Passport-PNG-Free-Image.png"
alt="Passport-PNG-Free-Image">
</div>
<div class="ID-application">
<h2><h2 style="color: lightskyblue;">ID Confirmation</h2>
<h3>Register to continue</h3>
</div>
</div>
</body>
</html>
You can view my full HTML and CSS on my full work on codepen: my full codepen work
besides the problem with the container for my passport image, the container on the right with the div class= "ID-application won’t display the text with a left alignment and a center aligned justified content despite me having already mentioning it in my CSS. Please help me fix this error. Thank you
I tried moving the display: flex atribute from an in-line CSS to the external CSS in hopes of making the page more responsive and placed both div containrers under the same div class that uses the flex property to make them appear side by sif=de equally but it hasn’t worked.
2
Answers
Percentage values for
width
andheight
are calculated with respect to the containing block, that is, the element’s parent.When we style a
div
withheight: 100%
, nothing appears to happen. That’s because thisdiv
’s parent is thebody
, which has no specified height. Thebody
therefore it takes its height from its contents: it is only as big as it needs to be.Styling the
body
withheight: 100%
doesn’t appear to help either.That’s because the
body
has a parent too: thehtml
element. Thehtml
element doesn’t have a parent, so the viewport is used as a surrogate parent for percentage size calculations. So when we stylehtml
withheight: 100%
(in addition tobody
and.d1
, we get the result we want:However, that’s not the only issue with your code. I’d use a grid to implement a side-by-side layout such as this.
I suggest you to add bootstrap, will help you to reduce your css and can do alignments and layout more efficiently and easily