1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    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,314
    Likes Received:
    372
    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