The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS centering divs horizontally on mobile devices

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #41783


    I’m in a bit of a fix. I’m working on a project and the method **div style=”margin:0 auto;”** works perfectly fine of a desktop, but gets messed up on mobile devices.(information getting randomly aligned as opposed to horizontal center). Strangely enough, on an earlier website , I used the “center” tag and _that_ seems to work like a charm. It even aligns itself beautifully in the landscape and portrait modes perfectly on mobile devices.

    I’m reluctant to use the ‘center’ tag as I’m told this tag will be eventually weeded out. Any suggestions?


    Use a stylesheet, not inline css. And you might have to fix your layout with media queries for mobile devices.


    just to confirm what you’ve heard, the center tag IS deprecated in html5.


    You set the width to 990px which won’t work on mobile as it’s much wider than a typical mobile viewport. You could try `max-width` but I would use media queries.


    I Did have a problem design for mobile once, where are give a white space on the right side of the device, to solve the problem I’ve used the meta declaration for view port from [H5BP](

    Inside my Head tag.
    Try it out, if don’t work let us know, and if possible host the code somewhere (on your host or codepen, gist, you know).


    For mobile devices, I tend to set divs to width 90% / 95% and then margin: 0 auto; them. But yea, don’t forget the meta viewport which will sort everything out for you :)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.