Allow image to be wider than containing div

19,055

Solution 1

You could position the image 'absolute'?

div > img {position:absolute;}

Solution 2

Set the div's width to 200px and its overflow to visible.

Share:
19,055
Krish
Author by

Krish

Hi There ✌, I am working with HTML,CSS,JS and Frontend frameworks (currently with React.js). I love to code in HTML/CSS explore and take challenges on that. Curious about web performance and optimization. Code Pen Profile See you out there. 😊

Updated on August 09, 2022

Comments

  • Krish
    Krish almost 2 years

    Is there any way to make a div not extend it's width, but make an image which is visible outside the div in IE8? For example, my div might be 200px wide, but the image 250px wide.

  • Marc Costello
    Marc Costello over 12 years
    This will give you the desired effect. Although personally i believe the container should always be large enough to hold it's contents. Maybe a different approach is required
  • Krish
    Krish over 12 years
    @marc constello:yep i tried that too, but the main thing is when i increase the width of the image the container div also increasing according to the width of the image so the image always be inside the container.. any way to fix this...?
  • Marc Costello
    Marc Costello over 12 years
    Are you giving the images set widths and heights?
  • Krish
    Krish over 12 years
    @marc constello:container div width:200px; image width:250px; and container div set with overflow:visible
  • Marc Costello
    Marc Costello over 12 years
    @krish the overflow:visible is not needed. just add div > img {position:absolute;}
  • Sagar Patil
    Sagar Patil over 12 years
    This should actually work. The absolute takes the image out of the regular flow of the document and hence will place it outside of the divs structural flow. Since it's out of the flow, the div should not expand. As @MarcCostello suggested, try it without the overflow.
  • Krish
    Krish over 12 years
    i used this but it remains the same
  • Mr Lister
    Mr Lister over 12 years
    But it works; I tested in IE8. Can you post the code you tried?
  • Krish
    Krish over 12 years
    @MarcCostello and Sagar patil: in IE the issue is fixed guys absolute was play its role... Thanks a lot.