Magento Expert Forum - Improve your Magento experience

Results 1 to 4 of 4

How block elements can be centered with CSS. ??

  1. #1

  2. #2
    Junior Member
    Join Date
    Aug 2016
    Posts
    41
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    There are three ways of centering a block with CSS as:-

    Centering with margins
    Centering with percentages
    Centering with absolute sizes.

    These are the multiple techniques for centering a block element, but techniques dependent upon the size set in percentages or in more absolute values.

  3. #3
    Junior Member
    Join Date
    Dec 2015
    Location
    USA
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    but I just got it. Since I don't see a way to delete the topic, I'll reply to myself, in case someone else is stumped by this.

    I just did a simple test in Codepen with a div and an image element inside. You can (horizontally) center the image within the div in either of these two ways:

    1) div img {display:block; margin: auto;}

    or

    2) div {text-align: center;}

    The difference is in the selector, whether you apply the style to the image or to the div. But both give the same result.

  4. #4
    Junior Member
    Join Date
    Oct 2016
    Location
    MONA TILES COMPOUND, NR. CHHANI CIRCLE, CHHANI ROAD, VADODARA - 390002. GUJARAT, INDIA.
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    1) div img {display:block; margin: auto;}

    or

    2) div {text-align: center;}

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •