Forums

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

Home Forums CSS center within div

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #27575
    kloy
    Member

    this might be a stupid question, but how can I center a photo in a div without using margins?
    Is there a rule for other elements like the ‘text-align’ rule?

    Thanks

    #69412

    you can use relative positioning or the "margin: 0 auto" trick

    #69430
    kloy
    Member

    Thanks, though I tried this and it didn’t work.

    I tried it with all positioning:relative and absolute

    #69438

    That may be the problem. Try "position: relative" instead of "positioning:relative".

    #69450
    mat
    Member

    I normally have this is my reset stylesheet for generic classes i want to use wsuch as img_center

    Code:
    .img_center {
    position: relative;
    display: block;
    padding: 0;
    margin: 0 auto;
    }
    #69509
    TheDoc
    Member

    You can also use "text-align: center;"

    #69516
    kloy
    Member

    I was using ‘position’ not ‘positioning’. I just used the word positioning in the post.

    I need to center horizontally, though not vertically.
    This looks like it will center both ways.

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