Jump to content

I want to make a full width banner for a website.

Currently my code is:

 

HTML / CSS

<img src = "images/banner.png">img {width: 100%;}

This makes the images stretch when the window is resized. What I would prefer to happen is if the window is resized than the edges of the image are cropped off.

 

If the width of the webpage was the same as the width of this image, I would want it to look like for example. Right now it would stretch to maintain the original aspect ratio of the image and this makes it's height change to a sliver if the webpage was actually this wide.

293429ee77.png

Link to comment
https://linustechtips.com/topic/258900-css-image-cropping/
Share on other sites

Link to post
Share on other sites

use these css properties for the div that contains the image

EDIT i'm sorry, you should add a class to the image and assign these properties to the class

max-width:100%;max-height:100%;

CPU: Intel Core i5 4690K @ 4.6Ghz CPU Cooler: Noctua NH-D15 GPU: GTX 1070 TI RAM: Crucial Ballistix Tactical 16GB (4x4) Mobo: ASUS Z97-PRO(Wi-Fi ac) PSU: Corsair RM Series RM750 Case: Fractal Design Define R4 no window

Link to comment
https://linustechtips.com/topic/258900-css-image-cropping/#findComment-3535704
Share on other sites

Link to post
Share on other sites

This does the same thing as before.

hmm strange, I found this on stackoverflow and if this doesn't work then I'm afraid I don't know it either

CSS:#im {    position: absolute;    top: 0;    left: 0;    right: 0;    bottom: 0;    background-image: url("path/to/img");    background-repeat: no-repeat;    background-size: contain;}HTML:<div id="wrapper">    <div id="im">    </div></div>

CPU: Intel Core i5 4690K @ 4.6Ghz CPU Cooler: Noctua NH-D15 GPU: GTX 1070 TI RAM: Crucial Ballistix Tactical 16GB (4x4) Mobo: ASUS Z97-PRO(Wi-Fi ac) PSU: Corsair RM Series RM750 Case: Fractal Design Define R4 no window

Link to comment
https://linustechtips.com/topic/258900-css-image-cropping/#findComment-3535860
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×