I am trying to make a horizontally and vertically centered div which does not have 100% width and height, but something like 80% both width and height. I just want to make kind of a box right in the center of the viewport. I am avoiding vh and vw units.
I found a solution like this :-
<div class="centered-box">
This is a box
</div>
And the CSS is
.centered-box {
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
position: absolute;
width: 80%;
height: 80%;
border: 1px solid black;
}
This works but when I use BootStrap3's .container class, this container misbehaves. The content also overflows. I think this is due to absolute positioning of the container. I just want a completely different concept. I dont want to use this method because of absolute positioning.