Forums

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

Home Forums CSS How to make an image center (horizontally) inside a bigger div? Using only css.

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #41502
    sandy
    Member

    I have a div 550 x 250 px. I want to insert an image (size width = 100px & height any size) in the middle of the div….

    #118401
    sandy
    Member

    @jurotek
    Thanks for reply. sorry mistake in my statement. your code only for fixed size of images. but i want to insert images of differ height…… please tell me solution for this issue.

    #118402
    Andy Howells
    Participant

    Why use absolute/relative positioning? Just use;

    img { display: block; margin: 0 auto; }

    Example pen: http://codepen.io/andyunleashed/pen/imdlA

    #118403
    sandy
    Member

    thanks @jurotek
    problem solved by using “display:table-cell” and “vertical-align:middle”. thanks for suggestion…..

    #118408
    EkingRDL
    Member

    You can use CSS calc unit

    .logo {
    margin-top: calc(50% – logoheight);
    }

    #118409
    Andy Howells
    Participant

    @ekingrdl – Whoa now, that’s overkill for what’s needed and browser support is pretty dodgy – http://caniuse.com/#search=calc

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