WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > WEB DESIGN > CSS > Trying to properly scale full-width image

Reply
  Thread Tools Display Modes
Old 8th August 12, 02:53 PM   #1
Fountain
WLC Member
 
Join Date: Aug 2012
Posts: 4
Default Trying to properly scale full-width image

(First forum post. Hello everyone!)

I am stumped. I am sure I am missing something obvious. My goal is to have a responsive image (1920x250) to always keep the height of 250px basically (except for mobile) and be full monitor width...WITHOUT distorting / stretching the image. If the window size goes below 1920, the left/right sides simply don't show as needed or scales properly. And if the window size is above 1920, the image then stretches, cutting the bottom of as needed, but doesn't distort it or go over the 250px height. I see many responsive sliders do this, but not sure how to set it up for a static image.

I have the following which works for the height, but distorts the image horizontally which I do not want to happen.

Any help or way to fix this or do it better would be appreciated!

CSS
#subimage {
width:100%;
position:relative;
padding:0;
min-height:250px;
max-height:250px;
overflow:hidden;
}


HTML
<img src="style/images/art/mantra-header.jpg" id="subimage" />
Fountain is offline   Reply With Quote
Old 8th August 12, 09:24 PM   #2
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Trying to properly scale full-width image

All you need is height:250px;
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 8th August 12, 11:38 PM   #3
Fountain
WLC Member
 
Join Date: Aug 2012
Posts: 4
Default Re: Trying to properly scale full-width image

Thank you for the suggestion. Applying just a height tag does not solve this specific issue.

Thanks.
Fountain is offline   Reply With Quote
Old 8th August 12, 11:39 PM   #4
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Trying to properly scale full-width image

What happens when you just apply the height tag?
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 8th August 12, 11:43 PM   #5
Fountain
WLC Member
 
Join Date: Aug 2012
Posts: 4
Default Re: Trying to properly scale full-width image

The following does not work, as it still distorts the image (obviously from the width tag). But we want a full width.

#subimage {
width:100%;
position:relative;
padding:0;
height:250px;
overflow:hidden;
}


Then we tried without the width tag, and the image is left static and does not scale the width for the responsive feel.

#subimage {
position:relative;
padding:0;
height:250px;
overflow:hidden;
}

I am sure I am just missing the obvious overall. Thanks.
Fountain is offline   Reply With Quote
Old 8th August 12, 11:45 PM   #6
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Trying to properly scale full-width image

If you want the height the stay the same, the image cannot scale without skewing the image. If you just want more of the image shown, then only set the height, not width. If you want the image centered, use margin-left:-XYpx where xy = (1/2 image width + 1/2 container width).
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 8th August 12, 11:50 PM   #7
Fountain
WLC Member
 
Join Date: Aug 2012
Posts: 4
Default Re: Trying to properly scale full-width image

Here is an example: http://themes.iki-bir.com/ikaros/

Granted they are using it in a slider, but same result. Look at slide two (the one with the guy on the phone). It stretches as needed, cutting off the bottom depending on the larger width, but still fills the max height and max width.
Fountain is offline   Reply With Quote
Old 8th August 12, 11:57 PM   #8
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Trying to properly scale full-width image

Okay, you're doing the opposite of what I thought. Set the width, and not the height.
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:35 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyright© 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.