+ 2
Header Background Image Container Size Scale
Hello, I want to use a background Image in my header. and it should scale depending on the size of the browser window. I got that working BUT it scales within the container. Meaning the container does not scale. So i need the container scale along with the image. If i use padding: 0px the image wonÂŽt even be seen. If i use padding: 130px There is a big white area when the window is small and no white area vene a loss of the image of what is being seen when the browser windows is big. Therefor the imgage is not recognized as existing. Am refering to the very first code of the HTML Fundamentals Course for "MyBlog" The code is even public on my profile. Anyone an idea? Thanks a lot for helping Helmut-Leonardo
10 Respostas
+ 4
Hello,
I'm not sure you're thinking of this, but try to replace your #header:
#header {
background-image: url(http://helmut-stremmel.de/Header.jpg);
background-color: #cccccc;
height: 225px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
See more: https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_background_hero
Or you can change image size with Media Queries, but it is more complicated.
See more: https://www.w3schools.com/css/css_rwd_mediaqueries.asp
+ 2
OK, I see. And what do you think about this?
https://code.sololearn.com/WquxNfV94Hgv/?ref=app
+ 2
Hi there,
you're welcome. Yes, I do. I speak a little german too. But neither my English nor my German is perfect. :-)
The point is how it appears in the browser, not in the SL playground. ;-) Somehow the display in the playground is not good. (The result what we see is not the same. I mean the different if you use the browser or the playground.)
I think your code is good without the property height="100%".
I don't understand what ratio do you think is good. If the width and height are the same, the image itself - because it is originally a rectangle - will be disproportionate. Do you need a square? I don't think so. This is why I think, that width="100%" and height="100%" - use at the same time - is not a good idea.
If you only set the width and the height is automatic, then the ratio will not change with the resize of the browser. Is that right? I don't need to scroll if I resize the browser and I always see the whole picture. It seems to me perfect in my browser.
You wrote "AND the container should always be the exact same size as the image". I see, but this is why the padding of 130px is a bad idea - no matter how big is the picture, the padding after that stays 130px and you see an empty white area in a smaller size of the window. Why do you need, why should be there a container?
So I'm not sure I understand the problem yet, but I'm really curious about it. ;-)
+ 2
You wrote earlier "Could it be that an image doesnÂŽt really exist for a container? Only Text?"
The reason is that you used it as a background image not a simple image (<img> tag). Those are two different things. If you want to see the background (the backgound image itself), you need to have some content in front of it (or above of it) - no matter whether it is a picture (like an avatar) or a text. But as a header image you shouldn't use it as background image if there is nothing in front of it (or above of it).
"width="auto" doesnÂŽt work." - It doesn't work by itself. This is not a surprise. "auto" means automatic. If the height is fixed, the width can be automatic. These two are related, e.g. height="100px" or height="100%" AND width="auto".
I'm from Budapest, Hungary. My mother tongue is Hungarian. :-)
Keep on coding. Viel GlĂŒck! ;-)
+ 2
You're welcome. :-)
+ 1
That ÂĄs not really it.
I would like to see the complete Image, no matter what size the Browser Window has AND i donÂŽt want to have get "white bottom".
The Code i just uploaded here on "My Codes".
Name is "Pizzeria Code".
ItÂŽs that image. I made black borders to see the "container".
I use a padding of 130px in .section so in my browser full open it looks perfect but when i size my browser down, the image sizes down, which is perfect, BUT the container doesnÂŽt. I have a big white bar bottom, probably because of the padding but i donÂŽt know what to do right now, because i donÂŽt want that white bottom respectivly the distance to the next container.
I just tried your solution but it sqeezes the image, which i already had as well.
And i thought maybe itÂŽs good to know for you that the image am using is actually a lot wider than height. (The problem with the header from my Blog code is the same yet not so obvious, i guess).
I tried three hours in a row today and couldnÂŽt find an answer. Maybe i donÂŽt have enough knowledge. I was thinking about floating or stuff. But yeah. Here i am.
Thanks for having a look at it.
I will have a further look at your links tomorrow, maybe thatÂŽll help ;-)
+ 1
DoesnÂŽt work either.
I had that before. The height stays exactly the same. and the width. ItÂŽs scrollable.
I like it to be completly seen no matter which dimensions the display / window size of the browser has.
AND the container should always be the exact same size as the image.
If i have no padding in ".section" the image is not even shown.
Could it be that an image doesnÂŽt really exist for a container? Only Text?
I use a padding of 130px because in my browser fully open it looks perfect.
If i shrink the window, i still see the complete image BUT because of the padding of 130px i get this big white border bottom to the next container.
Thanks for all your understanding and going through this with me ;-)
Besides, do you speak german?
+ 1
What i did rigght now.
I just had a look at HTML Fundamentals again and image and i came up with this.
https://code.sololearn.com/Wzlf31nycF8F
and it works perfect in Safari/Chrome/Firefox/Opera.
It just looks totally weired in the preview of the playground ;-)
BUT thatÂŽs the way i want it ;-)
And for the moment it is HTML with a tiny bit CSS (just for pre-wrap) ;-)
I donÂŽt know why i donÂŽt get it working that way with CSS, YET ;-)
I fuddled a bit more, i put the black borders around so you can better see what i meant:
https://code.sololearn.com/W04J98Ufx8Op
Do you see what i mean?
+ 1
height="100%" or height="auto" works fine.
width="100%" works fine.
width="auto" doesnÂŽt work.
I came up with the padding because i used originally the coding from the Sololearn-HTML-Fundamentals "MyBlog" in which the header is classified as Header in the CSS-Sheet.
Even now when i try to move the image and itÂŽs properties on to the CSS side, it wonÂŽt work anymore.
The CSS was the reason why i had those containers. I thought it is supposed to be.
However as it is working right now and because i donÂŽt need a pic or something within the image like an "Avatar" in a circle, i just keep it like that.
Next thing am working on is keep it fixed on top and let the rest of the page scroll underneath it ;-)
I will try and error and if i donÂŽt get it, i might ask here again ;-)
Where are you actually local? WhatÂŽs your mother tongue?
+ 1
Aaaahhhhhh.
Now i see ;-)
Thanks a lot ;-)