Resolution:
To center the div, start by setting .popup-content { width: 100%; }
and then nest your content within another div with display: table; margin: 0 auto;
View DEMO on JSFIDDLE
Rationale:
The attribute left: 50%
applied to your centered div .popup-content
leaves the left half of its parent empty, essentially utilizing only 50% of the available width.
Adjusting the width percentage will determine how much of the remaining space is occupied; for example, left: 30%
will take up 70%
of the parent's width.
The CSS property
transform: translate(-50%, -50%);
solely shifts the entire div without altering its dimensions.
Suggested CSS Approach:
If you aim for a dynamically sized, vertically and horizontally centered div, follow these steps:
Maintain vertical centering as-is, but expand the width to 100%:
.popup-content {
position: absolute;
top: 50%;
width: 100%;
transform: translate(0%, -50%);
}
Next, align the content horizontally by nesting it inside a div styled with display: table;
.popup-center-horizontal {
display: table;
margin: 0 auto;
background: red;
}
For a confined layout, set a max-width
limit like so:
.popup-center-horizontal {
max-width: 90%;
}
Compatible with IE8 and later versions.