Forums

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

Home Forums CSS set image to 100% unless container wider than image

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #269918
    jamesb0nd
    Participant

    Can you set an image to fill 100% of a container’s width except when the container’s width exceeds the image’s natural width?

    I find the distortion of the enlarged image more noticeble than the shrunken image.

    #269920
    bearhead
    Participant

    You should be able to do this by applying max-width:100%; to the img element.

    #269963
    Pranab
    Participant

    You can do that just to set the width of the image 100% and it will follow the container.

    Like that img{width: 100%};

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