Forums

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
    Posts
  • #41783
    Krish1980
    Participant

    Hello,

    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?

    #120000
    chrisburton
    Participant

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

    #120005
    dfogge
    Participant

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

    #120006
    chrisburton
    Participant

    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.

    #120074
    ooredroxoo
    Member

    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](http://html5boilerplate.com/).

    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).

    #120155
    lucas572
    Member

    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.