I can't seem to figure out why the border I applied to a child div
is not completely enclosing the element. I created two boxes using div
tags and added a border to one of them.
#box {
height: 500px;
width: 500px;
background-color: orange;
}
#upper-half {
height: 50%;
width: 100%;
padding: 0px;
border: 5px solid black;
}
<html>
<head>
<meta charset="utf-8">
<title>Height and width percentages</title>
<link rel="stylesheet" href="practice.css"/>
</head>
<body>
<div id="box">
<div id="upper-half">
</div>
</div>
</body>
</html>
The border doesn't fully enclose the "upper half" box.
To investigate this issue, I used the browser's page inspector and found that the dimensions of the box are 509.2 x 259.2.
I have a few questions regarding this matter:
Why is the box size 509.2 x 259.2 even with zero padding?
Why isn't the border completely enclosing the box?
Why does the border touch the left side, top, and bottom of the box as expected, but not the right side?