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.
if you don't wanna set a width for #container just add
to #main_content
You must assign a width to the div you want to center.
Like This:
More information and examples on these links:
http://www.w3schools.com/css/css_align.asp
http://www.w3schools.com/css/tryit.asp?filename=trycss_align_container
it would work giving the #container div width:80%[any width less than the main content and have given in % so that it manages well from both left and right] and giving margin:0px auto; OR margin:0 auto; [both works fine].
try this tested ok. live check on jsfiddle
I have used the following method in few projects
https://jsfiddle.net/u3Ln0hm4/
Make the css this way...
Working example here -> http://jsfiddle.net/golchha21/mjT7t/