Heartless Posted January 25, 2017 Share Posted January 25, 2017 Been working with bootstrap recently and have come across something that I'm struggling with. I'm trying to set the height of an image differently depending on the screen it is being used on. For example if I had a picture at 200px I want it to resize to 100px when I resize the screen to view on a mobile. Perfect example of what I'm trying to do here: http://frogspark.co.uk How do I go about getting the image to resize when making the window smaller? Is it done with css or javascript. Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2017 Share Posted January 25, 2017 In bootstrap, there's a class called "img-responsive" for images which basically sets the max-width to 100% and height to "auto". If it's a background image, with CSS you can set the background-size property to "cover". Link to comment Share on other sites More sharing options...
Heartless Posted January 25, 2017 Author Share Posted January 25, 2017 I have used the background-size property and set it to cover, and yes it does make the image responsive. But I was just wondering how they made the div size change depending on the screen size. When I go on that site and resize the window from large to medium the cover image height shoots down and does the same when it goes to mobile view. Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2017 Share Posted January 25, 2017 You can use media queries to set the height of something explicitly. .object { height: 200px; } @media (max-width: 1024px) { /* Devices up to 1024 pixels wide */ .object { height: 100px; } } Link to comment Share on other sites More sharing options...
Heartless Posted January 26, 2017 Author Share Posted January 26, 2017 Thank you, I will try that! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now