So, should be fairly straightfoward but i don't know why this isn't working (maybe i'm tired).
I'm trying to add position fixed to my webpage so i get a nice background that doesn't move, and then over the top, a text space where you can scroll (so the text moves, but the image stays the same). But when i add "position: fixed;" it just stops scrolling all together and as far as i'm aware, it should only stop the scrolling of the part it's attached to.
So here's my html
<div id="Home-background">
<div id="Home">
<a name="Home"></a>
<div class="page-padding"></div>
</div>
</div>
and my css
#Home-background {
**position: fixed;**
z-index: 1;
top: 20px;
width: 100%;
background: url('Pictures/lords-fallen-art-wallpapers-1080p.jpg');
background-size: 100%, 100%;
padding-top: 0px;
min-height: 700px;
}
#Home {
position: relative;
z-index: 10;
top: 400px;
width:70%;
min-height: 3000px;
background:#ffffff;
padding-top: 50px;
padding-bottom: 100px;
}
The marked position is what is causing the issue, but it should have no affect on the #Home set, right?
EDIT: I thought i should note, i am using other fixed elements ( i have a top bar and a menu bar at the side currently, both are fixed and both scroll till i add the fixed element as mentioned above. But having multiple fixed elements shouldn't stop other fixed elements from working either, right? (yes i've z-indexed them respectively)
#Home-background is wrapping the #Home div and will prevent scrolling if it is position: fixed
To place a fixed background, put a background on the body.
In your example it should look something like this:
no-repeat prevents the background image from repeating
background-position: fixed prevents the image from scrolling
background-size: 100% 100% stretches the image to fit the body element
Note: The image in this example does not make it obvious that it is fixed, but it is :)
body {
margin: 0;
background: url('http://www.placehold.it/1000') no-repeat;
background-size: 100% 100%;
background-position: fixed;
}
#Home {
position: relative;
width: 70%;
min-height: 3000px;
background: #ffffff;
padding-top: 50px;
padding-bottom: 100px;
}
<div id="Home">
<a name="Home"></a>
</div>
I managed to fix it, the problem was "Home" being inside "Home-Background" although i still don't understand why that would break it.
The following solves my problem
<div id="Home-background"></div>
<div id="Home">
<a name="Home"></a>
<div class="page-padding"></div>
</div>
Related
So, I know this is something that has troubled others before me, but I simply cannot make it work. I am currently working on a 1000px width centered background that should go on for the entirety of the page. With height:100%; I can get it to fill the entire screen, but if I have Divs within that requires scrolling, the background is missing at the bottom.
I have searched the internet to solve this problem and have found a bunch of solutions, though none seem to work for me. Among them:
Change body position to relative.
Change body and or HTML to 100% height and 100% min-height (and every combination between).
Change the position of my Divs to all the available positions (absolute, fixed, relative etc.)
Try to use table at the Body and then table-rows for my divs.
All the various overflow opportunities (I am not interested in scrolling within my Divs)
And many more.
Here is my code.
HTML
<body>
<div class="headerMenu">
<div id="wrapper">
something
</div>
</div>
<div class="signMenu">
<div class="div_one">
something
</div>
<div class="div_two">
something
</div>
</div>
</body>
CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height:100%; }
.signMenu {
padding-left: auto;
padding-right: auto;
width: 1000px;
margin-left: auto;
margin-right: auto;
position: relative;
background-color: white;
height:100%; }
.div_one {
background-color: rgb(250, 250, 250);
height: 1250px;
width: 400px;
position: absolute;
top:105px;
left: 0px;
margin-left: 30px;
}
.div_two {
background-color: rgb(250, 250, 250);
height: 1200px;
width: 400px;
position: absolute;
top:120px;
right: 0px;
margin-right: 30px;
}
Forget the headerMenu and wrapper for now. The point is, that if/when div one and two exeeds the height of the screen then the scroll bar appears, and when I scroll down the white background from the signMenu goes no further. I want that background to fill the enitire page (with scrolling down no matter how long), and not just the specific window size, which it does with height: 100%;.
I hope that makes sense. I am kind of new to this. Thanks in advance!
Let me first try to illustrate the problem
I have a webpage which contains a header and a sidenav. The sidenav is fixed in css, since I don't its content to move when scrolling.
When the page isn't scrolled down it works as intended, somewhat like this
However when I scroll i don't want whitespace on top of the sidenav. Currently when I scroll down the page, it looks somewhat like this
The intended behavior should be something like this
How do I go about this in css? Do I mess with the z-index of the elements? so the sidenav is behind the header when the page isn't scrolled? Or do I dynamically add to the sidenav's size when scrolling?
And how would either of these options be done in css?
As I understand, you have to set z-index of the header higher than the sidenav
Stack Snippet
.header {
height: 100px;
background: #000000;
position: relative;
z-index:999;
}
body {
margin: 0;
}
.sidebar {
position: fixed;
left: 0;
top: 0px;
width: 100px;
background: red;
height: 100%;
padding-top:100px;
}
.content {
height: 1000px;
background: yellow;
}
<div class="header"></div>
<div class="main">
<div class="sidebar"></div>
<div class="content"></div>
</div>
I have a site that as you scroll to the bottom of the content a "hidden footer" is revealed underneath the main content. The main content needs to be absolute positioned (as it is part of a larger "thing") and the footer needs a negative z-index and fixed position to have the right effect.
The thing is I got everything to work perfectly in Google Chrome, however the margin-bottom on the main content to reveal the footer does not work in Safari or Firefox. What gives?
I've tried the answers given in other questions (including a spacer div or various wrapper divs). Some of these solutions fix the ability to see the footer, however all of them now remove the ability to click on the links in the low z-index footer as they are now "covered" by a transparent div on top.
Here is a JSFiddle that shows the functionality (if you open in Chrome) and the problem (if you open in Safari or Firefox): https://jsfiddle.net/3npkmy6f/3/
Any help would be appreciated.
HTML:
<div class="main" style=""></div>
<div class="hidden-footer">
THIS IS A LINK
</div>
CSS:
.main {
height: 200%;
position: absolute;
width: 100%;
background-image: url("http://lorempixel.com/600/300/sports/1/");
margin-bottom: 400px;
}
a {
color: red;
margin-top: 200px;
left: 50%;
display: block;
text-align: center;
font-size: 50px;
margin-left: -25px;
}
.hidden-footer {
width: 100%;
background-image: url("http://lorempixel.com/400/200/");
height: 400px;
position: fixed;
bottom: 0px;
z-index: -2;
display: block;
}
Here is a solution with a wrapper and a spacer.
https://jsfiddle.net/Boloeng/3npkmy6f/11/
<div class="wrapper">
<div class="main" style="">
</div>
</div>
<div class="spacer">
</div>
<div class="hidden-footer">
THIS IS A LINK
</div>
However, bottom margin on absolute elements is probably something not specified (that would explain the different behaviors). So I would avoid this kind of approach.
I'm just working on a simple HTML page but still struggling with the divs.
The plan is: a fullscreen background and four horizontal buttons next to each other on the bottom. The buttons are currently mapped to the background image - so I could just add four invisible layers (divs) with some hrefs for example. Otherwise I would add them manually (in four single jpgs) to the bottom...
Howsoever, I want the whole site to (borderlessly) scale up and down to variable screen resolutions. Therefore also the sizes of the divs/images should scale equally and keep its position.
What I've got so far:
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
img {
height: auto;
width: auto;
min-width: 100%;
min-height: 100%;
}
<body>
<div class="background">
<div class="img">
<img src="background.jpg">
</div>
</div>
</body>
At this point I only have the background set up: its in an img-div within a background container with absolute positioning.
How could I add the four buttons now to stick at the bottom of the background a keep its relative size and position when the screen resolution changes?
:)
Take the button images out of the background image, set the body rules as follows (with background-image), add a div at the bottom and put the buttons in there (I chose DIVs with background-images for the buttons, but of course you can also use <button> tags. Adjust the "bottom" and button heights and the button margins as needed:
CSS
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
background: url(background.jpg) center center fixed;
background-size: cover
}
.bottom {
position: absolute;
bottom: 0;
left: 0;
height: 50px;
width: 100%;
text-align: center;
}
.button {
display: inline-block;
width: 80px;
height: 50px;
margin: 10px;
}
.button1 {
background: url(button1.jpg) center center fixed;
background-size: cover
}
.button2 {
background: url(button2.jpg) center center fixed;
background-size: cover
}
.button3 {
background: url(button3.jpg) center center fixed;
background-size: cover
}
.button4 {
background: url(button4.jpg) center center fixed;
background-size: cover
}
HTML:
<body>
<div class="content">
(your content)
</div>
<div class="bottom">
<div class="button button1">(button text 1...)</div>
<div class="button button2">(button text 2...)</div>
<div class="button button3">(button text 3...)</div>
<div class="button button4">(button text 4...)</div>
</div>
</body>
Thanks for the quick help!
The code looks good so far. But I still have the problem that the buttons change its size when I rise or decrease the screen resolution. Is there a way to give them fixed sizes in relation to the whole screen? "buttonX" should always have x% of the screens width and x% of its height... And I don't want the actual visible positioning resp. margin to change when the resolution changes :/
But many thanks so for!
I have a hard time to get background on both side of my page:
Style
.left {
background: url(wax.png);
width: 15%;
position: absolute;
left: 0px;
height: 100%;
}
.right {
background: url(wax.png);
width: 15%;
position: absolute;
right: 0px;
height: 100%;
}
.middle{
margin: 0 auto;
}
HTML
<div class="left">
</div>
<div class="middle">
</div>
<div class="right">
</div>
Result
Its close to what I am trying to achieve but the right image is misplaced.
Also the backgrund is not repeated vertically
background: url(wax.png) repeat-y 0 0;
To get the vert repeat.
Do you have something positioned relative? That input text field is probably pushing down the right div unless you have something else positioned relative?
If you're going to use position:absolute, wrap it all and use position:relative on that wrapping div.
Otherwise, you could use the body tag or even the html tag but it's probably better to use a wrapping container.
im not really sure what you are trying to do it looks align to me but for repeating image is this background: url(wax.png); background-repeat: no-repeat
Its close to what I am trying to achieve but the right image is
misplaced.
Add top:0 to the .right class
Also the backgrund is not repeated vertically
As others have mentioned add repeat-y in the background property value
background: url(wax.png) repeat-y
Maybe you just want to place your middle inside one div with the background repeated in both direction and middle having background white
html:
<div id="background">
<div id="content">
this was middle
</div>
</div>
css:
#content{
margin: 15%;
background: white;
}
#background {
background: url(wax.png);
}