I've got an problem. I have the html code like this:
<div id="main_content" >
<div id="container">
</div>
</div>
The css like this:
#main_content {
top: 160px;
left: 160px;
width: 800px;
min-height: 500px;
height: auto;
background-color: #2185C5;
position: relative;
}
#container {
width: auto;
height: auto;
margin: 0 auto;
padding: 10px;
position: relative;
}
I suppose that the #container will be centered within #main_content. However, it is not. I just want to find out the reason and how to make it centered.
Try to add
to your parent container css declaration. And following to child container:
It must do the trick.
Here is a new way to easily center your div using flex display.
See this working fiddle: https://jsfiddle.net/5u0y5qL2/
Here is the css :
here is the solution
to make a div in center. no need to assign width of the div.
working demo Here..
http://jsfiddle.net/6yukdmwq/
May be you want as this: Demo
html...
css..
How? >>> In a table cell vertical align with middle will set to vertically centered to the element and
text-align: center;
works as horizontal alignment to the element. Noticed why is #container is in inline-block coz this is in condition of row. Any question?