.content {
position: absolute;
text-align: center;
top: 50%;
}
.<your-outer-div> {
display: flex;
justify-content: center;
('align-items: center' will allow you to vertically center too ;))
}
You can apply this CSS to the inner <div>:
#inner {
width: 50%;
margin: 0 auto;
}
Of course, you don't have to set the width to 50%. Any width less than the containing <div> will work. The margin: 0 auto is what does the actual centering.
If you are targeting Internet Explorer 8 (and later), 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%
}
<div id="outer">
<div id="inner">Foo foo</div>
</div>
#inner {
width: 50%;
margin: 0 auto;
}
#inner {
display: table;
margin: 0 auto;
border: 1px solid black;
}
#outer {
border: 1px solid red;
width:100%
}
<-- Html -->
<div id="outer">
<div id="inner">Foo foo</div>
</div>
Code Example |
---|
Css :: hover media query |
Css :: css grid span columns |
Css :: css image overflow |
Css :: reset specific css |
Css :: css transparent background color |
Css :: ignore br css |
Css :: expo vector icons install |
Css :: outside padding css |
Css :: add inner border css |
Css :: background color css |
Css :: how to make all the columns equal size with flexbox |
Css :: rotate image in css |
Css :: css input radio checked |
Css :: text flow top to bottom |
Css :: transform:translateX() |
Css :: css crop image to circle |
Css :: input text size css |
Css :: ng-deep |
Css :: css how to change font colr |
Css :: input text only css |
Css :: add css to express app |
Css :: remove box around button when clicked |
Css :: inset boxshadow |
Css :: what are types of positioning in css |
Css :: drawing a circle with css |
Css :: remove contact form 7 css |
Css :: aspect ratio css |
Css :: select two stuffes css |
Css :: css focus change color |
Css :: css shrink image |