Image width doesn't change when resizing window in Firefox - html

I created a Fiddle here to illustrate the problem. Just try to vertically resize the preview window in Safari/Chrome vs. Firefox.
I need the images of my slideshow to be in the container .slideshow-elem. Some of them are tall and could fill up the whole height of the slideshow, some of them are not, that's why I can't give them a fixed 100% height. My goal is to vertically center those images which are not tall enough and let the others fill the entire slideshow vertically. All of this while keeping the aspect ratio and a dynamic width.
I have done this with the max-height attribute on the images and on the .slideshow-elem container. It works in Chrome and Safari, but not in Firefox.
Any ideas on how to get this done in Firefox? Thanks a lot!
Edit: Also I don't necessarily need the height to by dynamic when resizing horizontally. It is okay for the image to be cropped then. Therefore I updated the Fiddle...
Edit 2: Okay, so I took out max-width: 100%; on .slideshow-elem and it turns out that was all I had to do... Now the image scales properly on Firefox, too. But could someone explain this to me?

If you change .slideshow-elem img to
.slideshow-elem img {
max-height: 100%;
width: 100%;
}
It will scale properly in Firefox, from your question, you were mostly concerned with keeping the height, so I assume not having it set at max-width is not an issue.

Related

Stop background from adjusting to viewport size on a fixed width layout

My site is supposed to have a fixed width layout (Not responsive) with the background expanding the full width of the browser.
However when I shrink the browser the background gets cut off when it should stay at 100% full width. The same thing happens on an iphone and ipad, part of the background is cut off.
Website here: www.knockedupnowwhat.com
Im thinking that my css is wrong somewhere?
Thanks
You need to setup min-width:1140px on all container elements that have width 100%. so for instance your footer should look like this
footer {
background: none repeat scroll 0 0 #474747;
min-width: 1140px;
width: 100%;}
In the future, posting some of your code would be useful.
However the problem is because your div.container is set to 100% and it is your wrapper div. So when you resize the browser it will only be 100% of the browser, never wider. It's cutting off the backgrounds of it's child divs.

Dynamically sized images

I'm trying to add a responsive image to a front page that expands to the full width of the page. Similar to what many sliders do, but I only have one image so a slider is overkill. I've set up a div and set it's background image and background-size to 100% and that achieves the width. My problem is the height. I have to use a fixed height in order for the div to appear. I've tried setting height to auto, but then I don't get an image. I tried using this method:
How can I resize an image dynamically with CSS as the browser width/height changes?
but I can't seem to get the width to scale correctly. Using a fix height works fine until the browser window expands past the size of the image, and then it starts to cut off. Any thoughts on how I can make the height scale dynamically just as the width? Any thoughts would be greatly appreciated!
My code:
CSS:
.banner {
max-width: 100%;
height: 720px;
background: url(../images/homepagebanner.jpg) no-repeat left top;
background-size: 100%;
}
HTML5:
<div class="banner"></div>
I am using bootstrap, but this is outside of a container so it shouldn't be affecting this piece of code.
EDIT Here's the codepen:
http://cdpn.io/xLvzA
Have you tried setting the height of html to 100%, then setting the height of your banner to 100%? Adding a codepen demo to show your exact issue might help a bit better to help vizualize the exact problem you're having

Background disappears with scroll bar. Why?

Here's what I have: 800px width div's inside a 100% width container with a background image repeating horizontally.
Live: http://www.baskra.com
When I resize the browser window, a scroll bar is generated. When I scroll it, I see that the background image is only applied to the original unscrolled region, as seen above.
How can I solve this problem?
JSFiddle: http://jsfiddle.net/wcdXK (Not every image is working, but I believe the most important here is the CSS.)
You should replace the "width: 100%" from .pages-container CSS class with a "min-width: 800px" – it will force background to be the same width as the container if the window size becomes less than 800px.
.pages-container {
background-attachment: scroll;
background-image: url('http://baskra.com/images/bg/bg-scroll.png');
background-repeat: repeat;
min-width: 800px;
left: 0;
}
Check it here : http://jsfiddle.net/wcdXK/3/
Because the width applies to the area of the containing block, as the overall container is smaller the background shrinks to apply to the same area (along with the pages-container element).
I noticed you are experiencing many problems on your layout (you posted a similar question)
You should read a Responsive Web Design article trying to understand media queries
like this (random picked from google) http://www.onextrapixel.com/2012/04/23/responsive-web-design-layouts-and-media-queries/

setting an image as a footer background in CSS

So I'm looking to add a footer to my page but I want it to be a background-image that is automatically resized depending on the monitor resolution and have it with a 100% width and height but to never overflow to the sides, so I don't want scrollbars to appear. The image is .jpg.
Would appreciate some input as to what is the best way to go around this
Use the following CSS
​div {
width: 100%;
height: 400px;
background-image: url(your-path-here.jpg);
background-size: 100% 100%;
}​
And see this live example
Be careful, if you don't resize the height of your footer as well, that will stretch the image.
background-size will do the trick, but note that it' not supported by IE8 and older. Just to be on the safe side for these browsers, the image could be positioned in the center (that means at 50% horizontally and 50% vertically - of course, the center keyword also works)
Live demo: http://dabblet.com/gist/2790711

html/css issue.. full width background without scroll

I have been struggling with this for the past hour and I was wondering if any of you had any thoughts on this..
A client needs a nice big background image on the site. I cannot used this image as a background for the body or any div because I don't want it to be cropped horizontally. If the browser's width is smaller, the background should scale down.
So I just use an img tag with absolute positioning and z-index.
However(and this is where it gets tricky), the image is quite tall, and I don't want scroll bars on the side after the useful content.
Overflow=hidden on the body is useless because I do need scrollbars if the content is too much, but smaller that the image.
overflow=hidden on a div which has height,min-height and max-height set and contains the image just doesn't seem to work. I have no idea why.
And min-height, max-height and height is not working for the body tag either.
Any helpful ideas? I think this is doable by javascript, but I don't want to run a script every time the window is resized. I would prefer a html/css solution
PS: I have all browsers(opera, safari, ie8, firefox, chrome) open right now, and this is not just a browser issue.
I can't build a test case right now, but an absolutely fixedly positioned div with position: fixed; width: 100%; height: 100%; overflow: hidden and the image inside with width: 100% might do the trick. It will scale the image to the window's width, but won't create horizontal scroll bars.
The rest of the page may need a z-index to be displayed above the div.
Note that the body will have to have min-height: 100% for this to work.
position: fixed won't work in IE < 7.