Question
How can I horizontally center a
Answer
You can apply this CSS to the inner
#inner {
width: 50%;
margin: 0 auto;
}
Of course, you don’t have to set the width to 50%. Any width less than the containing
If you are targeting IE8+, it might be better to have this instead:
#inner {
display: table;
margin: 0 auto;
}
It will make the inner element center horizontally and it works without setting a specific width.
Working example here:
#inner {
display: table;
margin: 0 auto;
border: 1px solid black;
}
#outer {
border: 1px solid red;
width:100%
}