I want to set height 100% and width overflow to an image, so that on every screen the TOP Menu (Red Buttons) and the Footer Menu can be reached easily.
Left hand side and right hand site can overflow.
I tried
.stretch {
width:100%;
height:auto;
}
Withouth success. And changing values makes the image fullscreen and has not the desired effect.
Any Ideas?
Here's a fiddle: http://jsfiddle.net/H75BT/2/
Edit:
From Bigood's answer, I need this one to be centered : http://jsfiddle.net/H75BT/1/
Apply a 100% height on html & body, and define that your .stretch will adapt its height to the height of the body, and recalculate its width to keep the proportions :
html, body {
margin:0;
padding:0;
height:100%;
overflow-x:hidden; /* Add this to prevent the body to adapt its width if you need */
}
.stretch {
width:auto;
height:100%;
}
Working demo
Edit
You can make it centered by using CSS's background:
.stretch {
background-image: url("http://bockt.de/link/home.jpg");
background-repeat: no-repeat;
background-position: center 0px;
background-size: cover;
height: 100%;
position: relative;
background-origin: padding-box;
}
With a <div class="stretch"></div>.
Centered image demo
Related
I have made two forms on my website, both being surrounded by one <div class="wrapper"> tag. I used CSS to add a background image to this.
.wrapper {
background-image: url(../images/backgrounds/desktop.jpg);
background-size: 100%;
background-position: top;
width: 100%;
height: 100%;
min-width: 950px;
}
However, this is what the site actually looks like. I can't extend the bottom of the image to fill the screen. I can't figure out why it's doing this.
The height of div is 100% of what? If it is a direct child of body, the body is not wrapping 100% of the screen by default. So you have to make body 100% and then the wrapper will also take 100% of body. If there are more parent elements, all of them also should have style height:100% :
html,body{
height:100%;
}
Also add background-size:cover to make sure that the image stretch enough to cover the whole screen.
Add background-size:cover to have the background cover the entire div. Your background will only show behind the content contained within it. You need to change the height or padding of your container and/or add more content to see the whole background.
.wrapper {
background-image: url(../images/backgrounds/desktop.jpg);
background-size: 100%;
background-position: top;
background-size:cover;
width: 100%;
height: 100vh;
min-width: 950px;
}
My solution was to set the height of the <div class="wrapper"> to 100vh.
.wrapper {
height: 100vh;
}
This set the height of the divider to 100% of the window view height. Before it was going to 100% of the height of the forms.
Try replacing
background-image: url(../images/backgrounds/desktop.jpg);
with
background:url(../images/backgrounds/desktop.jpg) no-repeat scroll;
After Adding A background Image there is a white space left.
when bg-size is changed to 'cover' while re sizing to small resolution there is white space left please check yourself
codepen
body {
margin:0;
background-image:url('http://www.fg-a.com/wallpapers/yellow-flowers-green.jpg');
background-repeat: no-repeat;
background-size:auto;
}
You've got right the background-size:cover; but...
you're just missing the background-position property.
The simplest way is like:
html, body{
height:100%; /* Don't forget to set html and body to height 100%! */
}
body {
margin: 0;
background: url('green.jpg') 50%; /* where 50% is our background-position (center) */
background-size: cover;
}
that's really all you need.
http://jsbin.com/bogacad/1/edit?html,css,output
https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
I have a div with an unknown width. I want it to have a large background image.
How do I set the background image width to be as the width of the div itself? (the height of the div is known).
Background size will work, but the aspect ratio of the image will be changed. 500px below is the known height.
.myDiv {
background-image: url(image.png);
background-repeat: no-repeat;
background-size: 100% 500px;
}
More info on background-size here, it's not supported on <= IE8.
Or alternatively you could absolutely position an image relative to the container, but background-size is better.
img.cover {
width:100%;
height:100%;
position:absolute:
top:0;
left:0;
right:0;
bottom:0;
z-index:-1;
}
.myDiv {
background-image: url(image.png);
background-repeat: no-repeat;
background-size: contain; (you could also use cover here)
}
Use background image in the div and background-size css propierty.
Example:
#im {
background-image: url("path/to/img");
background-repeat: no-repeat;
background-size: cover;
}
You can also set the image width to 100% to fill your content div. In order to use height 100% you need specify your div height.
The following CSS attributes will make the background width fit to a dynamic container:
.myDiv {
background-size: 100%; /* fit width to container */
background-repeat: no-repeat; /* do not repeat background */
height: 200px; /* height is known */
}
See an example on JSFiddle
I have image of size 1400x560 and I want the my jumbotron div to scale to fit the size of the image. It works fine when i set the width of the jumbotron to that of the image but when I shrink the website to mobile view, I have issues. So how can I fix this?
I forgot to mention i have issue with the height and not the width, The jumbotron scales div to the width of 1400 but not to the height 560px
Here is a preview of the html page http://threeguys.us/rts/testing.html.
When i shrink the page , i want the image to resize according to the width of the browser
index.html
<div class="jumbotron">
</div>
css
.jumbotron
{
padding-top: 0px;
padding-bottom:0px;
background-image:url('images/car/car.jpg');
background-size: cover;
height:560px;
}
What you're looking for is background: contain;. Simply add this to your class as follows:
.jumbotron
{
padding-top: 0px;
padding-bottom:0px;
background-image:url('images/car/car.jpg');
background-size: cover;
background: contain;
width: 100%; /* make sure to define width to fill container */
height: 100px; /* define the height in pixels or make sure */
/* you have something in your div with height */
/* so you can see your image */
max-width:1400px; /* define the max width */
}
The background image will now scale with the size of the div (assuming the div is scalable). If you want to constrain your div so it does not get bigger than a certain size (in your case, the size of the background image), use max-width: 1400px;
See my JSFiddle example.
There isn't a way to get the div to fit the size of its background image, so I suggest you use an img tag instead.
To get your div to fit the size of the image, use display: inline-block on the div:
.jumbotron
{
display: inline-block;
border: solid red 1px;
}
<div class="jumbotron">
<img src="http://i.imgur.com/5LGqY2p.jpg?1" />
</div>
Try:
background-size: 100%;
width:100%
position:relative;
Hope it helps you
Wrap your jumbotron with:
<div class="container"></div>
It should make it fit width-wise to the rest of your page.
Make it simple. Thanks
.jumbotron {
background-image: url('https://stmed.net/sites/default/files/sky-wallpapers-28043-8362242.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
width: 100vw;
}
<div class="jumbotron"></div>
I'm trying to stretch an Image Full Screen (Cover): http://www.bootply.com/114850
I have a simple Menu and a call to action button but the image covers only the menu and stops there.
The Section Style is below.
.section-1 {
min-height: 100%;
background-image: url(http://i.imgur.com/fGrTemz.jpg);
background-position: center bottom;
background-repeat: no-repeat;
background-size: cover;
overflow: auto;
}
What am i missing?
Add
html, body {
height:100%;
}
section-1 is stretching to the height of its parent (html/body) which doesn't have a height set on so it doesn't know what height to be.
Change your min-height from percentage to pixels.
.section-1{
min-height:500px;
}
Percentage height is dependent on the height of the parent, so you need to "pass" the height in percentage to the targeted element.
html, body {
height: 100%;
}
Demo: http://www.bootply.com/114867
Yo specified position:absolute in your .content-holder so that it was removed from the content flow. As a result, its container <section> shrink its height to fit the <nav> element only.
Try remove position:absolute from .content-holder. And if you add position:absolute to .section-1, the background will be fullscreen.
Add the following to you css:
position: Absolute
so your css would be
.section-1 {
min-height: 100%;
position: absolute;
background-image: url(http://i.imgur.com/fGrTemz.jpg);
background-position: center bottom;
background-repeat: no-repeat;
background-size: cover;
overflow: auto;
}
if you add width:auto; to the section class. then just play around with the section-1 class min-height in "px" to target the screen size that best suits you. essentially what you could do is use media queries to target different screen sizes that way you will always get the perfect size. but thats alot of work so use the
html, body{height: 100%;}