2

At the moment I wasn't able to exclude the content-2 to outside the sticky content, without duplicating the element class format.

As you can notice in the following full-screen fiddle would result in:

.superlongcontent {
  height: 1000px;
  background-color: red;
}

.sticky {
  height: 300px;
  position: sticky;
  top: 0rem;
  height: calc(100vh - 20rem);
  overflow-y: auto;
  background-color: blue;
}

.content-1 {
  height: 600px;
  background-color: yellow;
}

.content-2 {
  height: 50px;
  background-color: green;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-lg-9 col-md-12 col-12 superlongcontent">

</div>

<div class="col-lg-3 col-md-12 col-12 sticky">
  <div class="content-1"></div>
  <div class="content-2 outsidesticky"></div>
</div>

Despite what I want to achieve which is placing the content-2 ( green box ) right below the sticky overflow content. Resulting:

If I duplicate the sticky using the same format it won't be that good at the moment:

.superlongcontent {
  height: 1000px;
  background-color: red;
}

.sticky {
  height: 300px;
  position: sticky;
  top: 0rem;
  height: calc(100vh - 20rem);
  overflow-y: auto;
  background-color: blue;
}

.content-1 {
  height: 600px;
  background-color: yellow;
}

.content-2 {
  height: 50px;
  background-color: green;
}

.sticky2 {
  height: 50px;
  position: sticky;
  top: 0rem;
  background-color: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-lg-9 col-md-12 col-12 superlongcontent">

</div>

<div class="col-lg-3 col-md-12 col-12 sticky">
  <div class="content-1"></div>
</div>

<div class="col-lg-3 col-md-12 col-12 sticky2">
  <div class="content-2 outsidesticky"></div>
</div>

If possible I don't want to duplicate the class like my current attempt:

<div class="col-lg-3 col-md-12 col-12 sticky">
  <div class="content-1"></div>
</div>

<div class="col-lg-3 col-md-12 col-12 sticky2">
  <div class="content-2 outsidesticky"></div>
</div>

Are there any better ways to achieve the same result?

1 Answer 1

1

Hope this solves your issue.

.superlongcontent {
  height: 1000px;
  background-color: red;
}

.wrapper {
  height: 300px;
  position: relative;
  top: 0rem;
  height: calc(100vh - 20rem);
  overflow-y: auto;
  background-color: blue;
}

.content-1 {
  height: 600px;
  background-color: yellow;
  /*Below css is for demo purpose only - to show the 'end' text*/
  display: flex;
  align-items: flex-end;
}

.content-2 {
  
  height: 50px;
  background-color: green;
}

.this-is-sticky {
  position: sticky;
  bottom: 0;
  width: 100%;
  left: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-lg-9 col-md-12 col-12 superlongcontent">

</div>

<div class="col-lg-3 col-md-12 col-12 wrapper">
  <div class="content-1">
    <span>END</span>
  </div>
  <div class="content-2 this-is-sticky"></div>
</div>

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

1 Comment

Thanks for the reply. Let me try in my project first. Is there any other way other than changing to relative wrapper?

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.