1

I've setup a parallax effect using css: JS Fiddle

Code:

body {
  margin: 0px;
}
header {
  height: 218px;
  background: blue;
}
#fold {
  background: red;
  height: 100vh;
  width: 100%;
  position: fixed;
}
main {
  background: green;
  position: relative;
  top: 100vh;
  height: 1000px;
}
<div id="fold">
  <header>header</header>
  fold content
</div>
<main>main content here</main>

At the moment, the 'main' div scrolls to the top of the body, but is there a way I can get it to stop when it hits the 'header' tag?

I do hope that makes sense. Thanks for reading, appreciate your advice.

2

1 Answer 1

1

Do you mean something like this?

body {
  margin: 0;
}
#fold,
header {
  width: 100%;
  position: fixed;
}
header {
  height: 218px;
  background: #00f;
  top: 0;
  left: 0;
  z-index: 1;
}
#fold {
  background: red;
  height: calc(100vh - 218px);
  top: 218px;
}
main {
  background: green;
  position: relative;
  top: 100vh;
  height: 1000px;
}
<header>header</header>
<div id="fold">fold content</div>
<main>main content here</main>

I moved the header outside the fold and gave it a higher z-index.

EDIT

Updated to match criteria

body {
  margin: 0px;
}
header {
  height: 218px;
  background: blue;
}
#fold {
  background: red;
  height: 100vh;
  width: 100%;
  position: fixed;
}
main {
  background: green;
  position: relative;
  top: 100vh;
  height: calc(100vh - 218px);
}
<div id="fold">
  <header>header</header>
  fold content
</div>
<main>main content here</main>

I've made the height of main be the same a the page height minus the height of the header. Using calc

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. Not quite, i'm not wanting the 'main' tag to go underneath the header, but to stop beneath it. So say for example the header has a height of 400px, im wanting the 'main' to scroll over the fold until it sits beneath the header, stopping at 401px;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.