100% bg container img width issue - html

I don't believe my question is exactly as the others posted on this site, so if i missed one apologies in advance to this excellent community.
My question is this:
i've setup a hero container below the nav container in order to give it an 100% but when i reduce the size of the browser the image (in the background of the hero container) scales down and doesn't take up the full dimensions of the container. I don't mind if the image shifts due to the fact that it's increasing and decreasing in scale i just don't want it to become so small that the foreground content gets left without a background
Here is a screen cast that illustrates what's happening exactly: http://youtu.be/lLT3VzHOlPU
Here is a codepen: http://codepen.io/MARS/pen/fEuKr
Thanks to anyone who takes the time to help out, much appreciated.

The video is a nice idea to describe your problem. :) You can use this CSS on the <div> with class hero-container. The background image will always fill the whole space but will never get distorted:
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
See here, which browser support the CSS3 Background-image options
Demo
Try before buy

Related

Resize image when resizes window

everyone!
I guess my problem is simple, but I can't figure out how to solve it :/
I would like to make an Image full height and full width, and when we resize the windows' width, the image resizes correctly like this example:
https://avada.theme-fusion.com/resume/
I already tried to play around with the width and height, but I can't have the same result
Thank you for your help !
The property you're looking for is background-size: cover.
body{
background-image: url('https://avada.theme-fusion.com/resume/wp-content/uploads/sites/66/2016/07/home_bg.jpg');
background-size: cover;
background-position: center;
}
You'll need to use a css background-image instead of an <img/> to achieve this result.
Here's a demo: https://jsfiddle.net/7rqm0mtb/
It would be ideal if you could post the code you're working with in order to get a better understanding on how you're going about this.
The Avada link you posted is using the image as a background-image, with the background-size property set to 'cover'. Take a look at this example on w3 schools.

White Space on Larger Monitors When Background Image ends

I am using Bootstrap, HTML and CSS for my website. I built it on my Macbook Pro, and now when I move to my desktop monitor (which is much larger), there seems to be a large white space on the right side of the web page due to the monitor being much larger in width.
The height is working perfectly fine and it scales well, but it seems like right when the image ends (width) the site wants to keep going, but is not stretching the image to fit the larger monitors horizontally (width).
How can I fix this?
Image of Website Problem:
This is what I came up with so far.
body {
background-image: url("http://i.imgur.com/vDF3k2s.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
width: 100%;
overflow: auto;
font-family: Lato;
}
html {
height: 100%;
}
I appreciate all suggestions, thanks!
Without your HTML code, I can't exactly replicate what you are doing, so I will have to assume some things... always dangerous! LOL!
Anyway, I will first tell you what I believe is going on, then I will explain some things to do to combat that, and then I will provide the actual code, based off of the code you have already supplied.
Ok, I believe what is happening is that since you haven't specified where within the body you want the background image, by default the browser is giving you the image at 100% of it's original size and floated to the left.
In order to get a fullscreen image, which is what I believe you are shooting for, I would first place the background image within the "html" tag instead of the "body" tag. Second, I would let the browser know that you want the image to be centered and not to repeat. Then I would tell the browser that you want the image to "cover the screen".
So, with that said, here is the code for what I just explained:
html {
background: url("http://i.imgur.com/vDF3k2s.jpg")no-repeat center;
background-size: cover;
overflow: auto;
}
I should explain that I have deleted the -webkit, -moz, etc. portions of the code. That is because "overflow" is compatible with so many older versions of the most commonly used browsers, that to write that in your code is unnecessary.
Also, when I'm creating a fullscreen background image on a page, I usually use "background" instead of "background-image" and I have the "overflow" as "hidden". I can't honestly tell you if that is a "best practice" or if your writing "overflow" as "auto" is, but I also don't know what other content you plan to put in place, etc.
Anyway, I hope my solution helps and please hit me back to let me know!

How to resize background image on Safari?

In Chrome
In Chrome, it works just like the picture above.
In Safari
However, in Safari, it does not work as shown above.
The CSS code is as follows:
background-image: url(rendyhome.png);
background-size: auto 66vh;
background-repeat: no-repeat;
background-position: right;
How do I fix it?
background-size: contain;
You can try with the following code that tell the browser keeping image inside the container, then, to center it. This solution may create a blank color around the image that can be filled using background color;
background-size: contain;
background-position: center;
https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
A keyword that scales the image as large as possible and maintains
image aspect ratio (image doesn't get squished). Image is letterboxed
within the container. When the image and container have different
dimensions, the empty areas (either top/bottom of left/right) are
filled with the background-color.
background-size: cover;
You can also use background-size: cover; that will entirely fill the screen with your image.
Be careful: using this technique, you need to know the image may be cut by the browser if the screen ratio is not the same as your image (think responsive). As I can see on your image, there are some wording inside, so the cover solution may be inappropriate to keep them visible.
When the image and container have different dimensions, the image is
clipped either left/right or top/bottom.
Both solutions are good, but effects are different. It depends on your behaviour preference. Even if image ratio is respected in both solution, one solution clip/cut and the other create a blank around the image.
This is an image from marcarea.com, in order to summarize. You can see behaviours I described before.
Look here:
https://www.w3schools.com/cssref/css3_pr_background-size.asp
I would look at using
background-size: cover;
Scale the background image to be as large as possible so that the
background area is completely covered by the background image. Some
parts of the background image may not be in view within the background
positioning area

How do I make a full width picture extend, through using CSS, without effecting the quality of the picture?

I have been doing some HTML and CSS and have come across a problem that I hope someone can help with.
I am trying to make a full width picture cover a whole Div without a significant loss of quality to the picture.
An example of what I am trying to achieve is similar to the following websites:
https://sso.godaddy.com/v1/?app=mya&realm=idp&
http://www.ugle.org.uk/
Both websites use a picture which quality seams to not dissolve through being expanded or contracted.
How is this done?
Any one know of any tutorials or have example code that they could show me. I have created a picture that can vary to the browsers window size but its quality is awful when the browser changes size.
Thanks in advance everyone!
Very easy. There are a few ways to do this, but the most straightforward is to set the image as the background of the div, with the background size property set to cover: background-size: cover;
For example (CSS):
div {
background: url('path/to/your/image.jpg') no-repeat center;
background-size: cover;
}
Edit: Addressing image quality:
You'd need to make sure your background image is equal to or larger than the div's dimensions. If it's smaller - it'll be stretched to fit (this degrading the quality).

Why does the background image not cover the whole page sometimes?

I have an HTML page where I have an image as a background. Whenever I view the page on my iPhone 6, the background image sometimes doesn't cover the whole page. This happens only about 20% of the time and doesn't happen after reloading the page. It always happens when I clear cache and website data on my phone. This is the CSS to set it to the background(I got it from the web by searching "how to make a good CSS background image")
html { /*Copied from the web*/
background: url(img/sea.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body{
background: none;
}
The url of the page is msolonko.net/signup.php.
As you can see on the image, there is white space below the login button. Why does the image work correctly sometimes, but rarely not? How can I fix this?
EDIT:
Changing resolutions of the image has no effect on the issue.
I do not want the image to repeat. It looks good with just one image if the issue doesn't occur.
Also, if I cannot fix this issue, I will make the image only appear if it is a computer. If the device width is less than some threshold, I will just use a background color instead of image. I am still hoping I can fix this though.
Two solutions: Make it so the image repeats (turn no-repeat to repeat) or..
Increase the height of sky.jpg since sky.jpg is not tall enough to fit the phone.
So if I'm not mistaking (which I probably am), you should make your sky.jpg image 960 x 660 pix. Some average phone pixel resolutions at http://www.binvisions.com/articles/tablet-smartphone-resolutions-screen-size-list/
This should help! Sorry if it didn't.
EDIT: Did you at least try the techniques? (I'm new to Stack, I can't comment)
edit the image before you load the page, make the correct size for it and there you got.
be recursive.
(i have the same problem and do it this way becouse i found no way to find a solution in the code.)
i use programs like photoshop and corel.
I got it! I was learning some CSS... CSS Code:
body {
background-image:sky.jpg; /*or whatever*/
}
Should work...maybe.