Centering and Expanding Image with CSS only

Discussion in 'Web Design, HTML And CSS' started by Ami Desai, Feb 6, 2017.

Tags:
  1. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    http://www.ifourtechnolab.com/
    Hi,

    In a gallery site I need to show photos. I am having a div, wrapper. It contains an image tag. The picture should expand and fill the parent element. Along with that it should be centered vertically and horizontally. The size of the image and the container could vary.

    Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You should be using the background of the div element as an image if you want to fill the image because if you use img tag, it will leave some space unfilled if the image aspect ratio does not match.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice