Home > Enterprise >  How do we make the sidebar sticky using css?
How do we make the sidebar sticky using css?

Time:06-02

Sitcky sidebar

I need to make the cre_asideCol column sticky. But I am facing some issues with this and am not able to create this sidebar sticky.

CodePudding user response:

I would set position: sticky. However you must pay attention to the attribute of top, what you have set, because that's gonna mean, the sidebar will stick from that point on. So if you have position:sticky, top:20px, that will stick after the scrolling go above 20px.

CodePudding user response:

Now the issue solved

    overflow: inherit;
    align-items: flex-start;

We need to add these CSS properties to the parent element of the sidebar.

CodePudding user response:

With css you should write to the sidebar:

position: sticky;
top: 0;

You might need to add additional tag wrapper, in order for sticky positioning to work

.entry-content {
  width: 400px;
  height: 400px;
  background-color: aqua;
  position: relative;
}

.sidebar {
  position: sticky;
  background-color: red;
  width: 375px;
  height: 100%;
  left: 0;
}

.menu {
  position: absolute;
  right: 0;
}

.cre-asideCol {
  position: absolute;
  left: 0px;
  background-color: orange;
  width: 300px;
  height: 100%;
  overflow: auto;
}
<div >
  <div >
    <div >
      <nav>menu 1</nav>
      <nav>menu 2</nav>
      <nav>menu 3</nav>
      <nav>menu 4</nav>
      <nav>menu 5</nav>
    </div>
  <div >
    <p>
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    </p>
  </div>
  </div>
</div>

  • Related