I have made a page that starts with a full (100% by 100%) image div.
This div will always fill up the page before scrolling.
Then I have another div with an image.
On desktop there is no problem.
However, on mobile when this page is loaded and I swipe my finger to give it a little scroll, then when the phone finished scrolling, it snaps / auto scrolls back a bit. It also appears to zoom-in a little.
I think it's due to the 100% on HTML and BODY tag, because if I remove that, then there is no scrolling correction.
I have tried this on several Android phones and always the same. How do I fix this? Here's the code.
<style>
* {
box-sizing: border-box;
margin: 0;
}
html, body {
height: 100%;
}
div {
width: 100%;
height: 100%;
}
div.first {
background-image: url("http://i.imgur.com/VWYl1EC.jpg");
background-attachment: fixed;
background-size: cover;
}
div.second {
background-image: url("http://i.imgur.com/PbV1Grl.jpg");
background-size: cover;
}
</style>
<div class="first"></div>
<div class="second"></div>
Problem is when the first div on a page has a height in %, this auto correction scroll will happen on Android phones.
The solution is to set the height in PX instead by using jQuery.
For example:
$('.firstdiv').css('height', $(window).height() + 'px');
use your css like following:-
<style>
* {
box-sizing: border-box;
margin: 0;
}
html, body {
height: 100%;
}
div.first {
max-width:100%;
background-image: url("http://i.imgur.com/VWYl1EC.jpg");
background-size: cover;
height:300px; /* as you needed */
}
div.second {
max-width:100%;
background-image: url("http://i.imgur.com/PbV1Grl.jpg");
background-size: cover;
height:300px; /* as you needed */
}
Related
I have this login page with a footer. the footer keeps chaning its height to the extent that it overlaps with the body. If someone plesae can help. I do not what is going on here. I would like to have the height fixed with no overlaps while taking into account the resizing
this is my css
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 30px;
margin-top: auto
}
I removed position it seems better, but the footer has become outside the body/html background
this is the css of html and body
html, body {
height: 100%;
background: url('../images/bg.jpg') no-repeat;
background-size: cover;
}
I can only assume, but i can see what's wrong. Try this:
html, body {
min-height: 100%; /* fixed it, because the regular height 100% will cause that white background of footer*/
}
body {
/* we need background image only in body */
background: url('../images/bg.jpg') no-repeat;
background-size: cover;
}
.footer {
/* we should remove position or set it relative */
width: 100%;
white-space: nowrap;
line-height: 30px;
margin-top: auto
}
Should work perfectly.
I am trying to get my background to fill 100%. It currently is on every page except where the content gets too large (see photo (http://i58.tinypic.com/2n18hn8.png)). I have tried a bunch of different things to fix it but nothing is working. If I change the #page-wrapper to 3000px it will display the background fully, but then is too large on other pages. Please help
html,
body,
#page {
height: 100%;
}
#page-wrapper {
min-height: 100%;
min-width: 960px;
}
In your body class
body{
background-size:cover;
background-image: url('img/cover.png');
background-position: top center;
background-attachment: fixed;
background-repeat: no-repeat;
background-color: #000;
overflow: hidden;
}
Try this and let me know what you think.
I've found a similar question here but with no answer, yet I can't find an alternative as a solution.
I have the following code and it works perfectly on Mac and Windows, however I can't figure out why on Android (either Chrome or Firefox) the background does not get updated when the user is scrolling down, it produces the space of about 1/5 of the screen at the bottom while scrolling down.
The background image gets updated after you release the touch.
html{
background-image:url(example.jpg);
background-position:fixed;
background-size:100% 100%;
}
Specify a height for your html and body, i.e.
html {
width: 100%;
height: 100%;
}
And
body {
height: 100%;
min-height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
And add a div that will wrap everything inside body, i.e.
<body>
<div id="wrapmeup">
....your content....
</div>
</body>
And finally add this to your css:
#wrapmeup {
height: 100%;
width: 100%;
background-image: url(image/background.jpg);
background-attachment: fixed;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
Here is the page I am trying to apply this full screen image to:
http://www.alexwiley.co.uk/portfolio
I wish to make it so that the image displays 100% width and 100% height until you scroll down, then you can see the content below this as you scroll.
Here is an example site of what I am looking to do:
http://www.nilsfrahm.com/
You can see his image is fullscreen until he scrolls.
I am making this website in Adobe Muse CC just as added information.
You need to use background-attachment: fixed; with background-image and background-size: cover;
Large screen version: http://codepen.io/suez/full/wulBv/
* {
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
}
html, body {
height: 100%;
}
div {
width: 100%;
height: 100%;
}
div.first {
background-image: url("http://i.imgur.com/PbV1Grl.jpg");
background-attachment: fixed;
background-size: cover;
}
div.second {
background-image: url("http://i.imgur.com/VWYl1EC.jpg");
background-size: cover;
}
<div class="first"></div>
<div class="second"></div>
Try adding position: fixed to the div that has the background.
I'm trying to do a background image of 100% and have an image as the background. When I upload the image it goes to 100% but it cuts off have the picture. It makes the image wider than my screen. How do I fix it where the picture width is 100% but the image width fits the screen without getting cut off. Here is my tumblr to let you see what I mean (http://ophelialogy.tumblr.com/) and here is the full image to show you the full image and give you an idea for where it's cutting off (http://imageshack.us/a/img7/7103/khb3.png).
Here is my code:
CSS PART
/* --- HEADER --- */
#header {
top: 0;
left: 0;
width: 100%;
{block:IfAdjustableHeader}height:{text:Header Height};{/block:IfAdjustableHeader}
{block:IfNotAdjustableHeader}height:100%;{/block:IfNotAdjustableHeader}
position: fixed;
z-index: 10;
background-image: url('{image:header}');
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* --- PAGE CONTENT --- */
#page {
{block:IfAdjustableHeader}top:{text:Header Height};{/block:IfAdjustableHeader}
{block:IfNotAdjustableHeader}top:100%;{/block:IfNotAdjustableHeader}
left: 0;
width: 100%;
min-height: 100%;
position: absolute;
background: {color:Background};
z-index: 99;
}
.container {
margin: 50px auto 0px;
{block:If400Posts}width: 800px;{/block:If400Posts}
{block:If500Posts}width: 900px;{/block:If500Posts}
}
/* --- POSTS --- */
.postcol {
width: 540px;
margin-left: 240px;
}
.posts {
margin-bottom: 20px;
background-color: #fff;
padding: 20px;
}
.posts img, .posts li, .posts blockquote {
max-width: 100%;
}
HTML Part
<body>
<div id="header">
<div class="description">{Description}</div>
</div>
<div id="page">
<div class="container">
<div class="postcol">
{block:Posts}
<div class="posts">
</div>
this excellent blog post explains exactly what you need, without any third party tools:
http://css-tricks.com/perfect-full-page-background-image
also, there are some jQuery plugins for that, including:
https://github.com/jaysalvat/vegas
https://github.com/buildinternet/supersized
SO...
What cover does (in my mind) is take the background image and do it's best to use the most of it that it can depending on the height or width of the box it is in. There are 2 ways to deal with this. One way is to make the box the perfect ratio for the image. The other is to actually use an img that will stretch the box to it's exact size. Here is how to do each. The plus of the background-image version, is that you can easily only serve a small version to small screens with an #media rule.
HTML
<header class="container global-header"></header>
<header class="container global-header2">
<img alt="banner-thing" src="http://placekitten.com/400/100" />
</header>
CSS
html, body {
height: 100%;
margin: 0;
}
.container {
width: 100%;
float: left;
}
.global-header {
width: 100%;
/* this is hacky - but it is your answer */
height: 0;
padding-bottom: 25%;
background-image: url("http://placekitten.com/400/100");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
/* you should have this too */
background-position: center center;
}
.global-header2 {
width: 100%;
/* height will be determined by image size */
}
.global-header2 img {
display: block;
width: 100%;
height: auto;
}
FIDDLE
use:
background-image: url(../images/myimage.jpg);
background-size: cover;
Do you want the background image in the header or on the main page?
It is currently in the header.
Set the background image on the html tag if you want it to cover the whole page.
Nasser's link to do that is a good one (I would leave out the browser specific hacks though).
EDIT
AHH You're talking about width.
I think it might be something to do with the irritating slider tumblr have coming in from the right - it is about that much too stretched.
I suggest trying these styles on jsfiddler - or another separate site - you'll probably find it works fine.