We are trying the new look for our home-page where the background image takes the entire screen area.
However the images we are using as the background image are getting cropped at the Top and Bottom of the image, resulting in not the best look & feel that we would like.
As an example, here is the image that should be loaded:
And here is the CSS code we use for this is:
.bg_w_foto {
background: url(images/cities/<?php echo $city_name; ?>) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Do you have idea how to solve this? So that entire image is stretched to display as the background image.
Your background is applied to a cell in a single table row, so it will never extend beyond that one row.
I donât want to sound harsh, but you need to join us in the 21st century and stop using tables to layout your website. Then great thing will start to happen, for one you will solve this problem.
This is the css I use for full screen backgrounds:
You canât stretch an image to fit its container dimensions because that would squish the image and would look bad. You have to maintain the aspect ratio when resizing images and that means that when the width is increased then the height must also be increased accordingly which will maintain the correct aspect ratio of the image.
Background-size:cover take an image and make sure that the image fully covers the container it is placed in but in order to maintain the aspect ratio the actual image will of course need to be bigger than the container (unless by some chance their aspect ratios are the same).
If you think carefully about what you are asking then how else could an image cover the background. You canât just stretch the width and height to fit as that makes the image distorted.
As mentioned above if your image was a full page image then there is not much of a problem as it would fit better but as you are trying to squeeze it into 250px height then something has to give because the width of the image needs to be very wide to fill the screen.
When you choose images you should take this into account and its better to have images that have a smaller centred focal point which will make it better when they are scaled to bigger or smaller screens. If you only want a narrow letterbox effect then choose images that have better aspect ratios for that and not nearly square like your image above.
WebMachine, sorry if I was not clear. We want the background image to cover just that Cell of the Table and not the entire home-page. So we want it to stretch to display fully in that Table column (cell), and not the the entire home-page but for the image not to be cropped at top and bottom as it is now.
The whole image is visible, but the bridge appears squashed. Because the height is fixed it squashes more the wider your screen is. Is that what you want?
Well the loss of aspect ratio, makes the bakcground images to look horrible
So that is not acceptable solution obviously.
So then what should we do? Have images that are shot with a Wide Lens?
So what should we do?
That is how should we have background images over that Cell which is not cropped at top & bottom?
I guess answer is to have Wide Angle Shot? Right?
If yes, can you suggest where is best place to get such Photos?
Yes, I explained in my post that you should choose images of letterbox proportions and not square. Its a simple mater of mathematics and very little to do with css.
You canât stretch an image unless you maintain aspect ratio so wider images mean taller heights as well if you want the whole image. How else can it work?
Iâm afraid I donât have any suggestions for where to get images from as I leave that to the designers to come up with but you must choose carefully and I would choose images with a smaller central focal point so that when stretched they still stay in your letterbox view.
Will itâs not a round hole, but same principle. You are trying to put a shoe-box through a letter-box, it does not fit! You must either chop it or squash it to fit.
Either be happy with that shot cropped, or find a shot in a wide aspect.
In addition, if you want to retain a fixed aspect (have no cropping of your wide aspect image) donât have a fixed height combined with a variable width as you have.
So you could have width: 100%; height: 20%; I say 20% there, but whatever % creates the desired aspect.
I have exactly that here, all the header photos are 900 x 200 px in size (also set in the img tag), in css the container has max-width: 900px; and the id for the image is 100%; height: 20%; to maintain that aspect.
SamA74,
You should read before throwing and insulting response!
As stated already, we have already arrived at what you have stated with your insulting âsquare pegs and round holesâ analogy and are now at the phase of asking:
âwhere can we find the suitable photo dimensionsâ?
And also as per PaulB suggestion Photos that have âimages with a smaller central focal pointâ.
To be exact, we need then the correct Photo dimensions, which are high quality (resolution) of World Cities. So where can we get or Buy the Photos which would fit this theme and are:
" letterbox proportions"
&
âhave smaller central focal pointâ.
Sorry, I did not intend to sound insulting. My apology for any offence.
I was just trying to illustrate the point so it was easy to understand, I got the impression you had difficulty grasping the idea.
That link leads to photos of Golden Gate Bridge only.
We need Photos of World Top Cities (Sites), of which of course GG is one.
And of course as per this discussion we need the Photos to be:
High resolution photos of Cities that are of letterbox proportions and have smaller central focal point
FYI, I have searched for this phrase on Google and have found nothing really.
So any suggestions where we can find such photos for free or paid, would be great.
I canât help you with finding images Iâm afraid but just to illustrate the point I have been making if you choose this image from the link that Sam shown above and test it instead of your own image (also change css to background-size:cover) you will see that it scales much better and doesnât lose its impact.
As I replied, we have ALREADY chosen that wide image of GoldenGate. We just need more such images of World Great Cities (sites) beside that one image. And as I wrote I searched online but so far cannot find any more such wide images for free or even for paid.
That is why I was hoping you all could suggest a good site for such Wide images.