Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center with margin auto doesn't work

Tags:

css

margin

I use a jQuery animation in my page which adds some CSS properties and I don't understand why the margin: auto doesn't work.

The HTML code (with style properties added by jQuery) :

<body style="overflow: hidden;">
    <div id="tuto_wamp" style="width: 7680px; height: 923px; ">
        <!-- Step 1 -->
        <div style="height: 549px; width: 1280px; margin-top: 0px; margin-left: 0px; position: absolute; overflow-y: hidden; overflow-x: hidden; ">
            <div class="content_tuto">
                <img src="images/install1.png" alt="">
            </div>
        </div>
    </div>
</body>

My CSS code :

#tuto_wamp 
{ 
    background: #3a393c;
    width: 100%;
}

.content_tuto
{
    width: 100%;
    margin: auto;
    display: block;
}

I don't know which property blocks the margin: auto to center the image.

Thank you.

like image 505
Guillaume Avatar asked May 16 '12 15:05

Guillaume


2 Answers

I know this is an old post, but wanted to share how i solved the same problem.

My image was inheriting a float:left from a parent class. By setting float:none I was able to make margin:0 auto work properly. Hope it may help someone in the future.

like image 151
Ryan Hollingsworth Avatar answered Sep 23 '22 19:09

Ryan Hollingsworth


Add text-align:center; to .content_tuto and it will center

Note, you have the widths style="width: 7680px; ... and style=".. width: 1280px; ... , so when you center you are centering for that width.

like image 34
Sully Avatar answered Sep 26 '22 19:09

Sully