It is always recommended to mention height to the parent/grandparent before you use height:100%
to a child element
Try this
.circle {
max-width: 150px;
width: 100%;
max-height: 150px;
height: 100%;
display: block;
background: #ff4040;
border-radius:50%;
}
body{
height:100vh;
position:relative;
}
<div class="circle"></div>
If you still don't want to mention height to the body element(parent) you can define them like this
Because by default the div elements' were block
elements
Block elements always have 100%
width but not a definite height
so define the max-width the actual size and set its width
to 100%
so that it won't escape the given width.
But when it comes to height divs don't have heights by default so here set height
or min-height
to your required value and add max-height:100%
(optional)
A block-level element always starts on a new line and takes up the
full width available (stretches out to the left and right as far as it
can)
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
.circle {
max-width: 150px;
width:100%;
max-height: 100%;
min-height:150px;
display: block;
background: #ff4040;
border-radius:100%;
}
<div class="circle"></div>