0

Basically, I want to position the div class i.e the navigation bar "basehead" to the bottom of the parent element i.e "header" and make it sticky at that position so that if the webpage is scrolled, the navigation bar appears at the top at every instant.

    /* Parent Element */
    .header{
        height: 500px;
        background-color: #e260b1;
        position: relative;
    }
    /* Element to be stiked at bottom of parent element */
    .basehead{
        width: 100%;
        background: #333333;
        height: 60px;
        position: sticky;
        bottom: 0px;
    }
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356

3 Answers3

0

Try this:

#first you need the set the div element in bottom using

bottom: 0;

no need to put "px" after the value.

Then to set it to a fixed position use

position: fixed;

or you can check this tutorial in w3school about fixed menus https://www.w3schools.com/howto/howto_css_fixed_menu.asp

0

When you are using position:sticky; it means it will stay sticky to its parent element. So consider nesting the .basehead element at the top of the <body> tag, if you want the element to appear on top of all other elements when you scroll.

HTML:

<body>
  <div class="basehead">*Your content here*</div>
</body>

CSS:

.basehead{
  position: sticky;
  top: 0;
}

Here, I provide a link to see how this works.

0

The outer div does not have any content to make it scroll, to make the html work we must make the outer div have some minimum height like

.header {
   min-height: 1000px;
}
.baseheader {
   position:sticky; top:0;
}
<div class="header">
  <div class="baseheader">HEADER</div>
</div>
<p>some content 1</p>
<p>some content 2</p>
<p>some content 3</p>
<p>some content 4</p>
<p>some content 5</p>
<p>some content 6</p>
<p>some content 7</p>
<p>some content 8</p>
<p>some content 9</p>
<p>some content 10</p>
<p>some content 11</p>

The inner div will not pin to bottom unless a sibling element pushes it down so put a tag above it to push it down with a min-height

.header {
   min-height: 1000px;
}
.baseheader {
   position:sticky; bottom:0;
}
<div class="header">
  <div style="min-height:1000px"></div>
  <div class="baseheader">FOOTER</div>
</div>
<p>some content 1</p>
<p>some content 2</p>
<p>some content 3</p>
<p>some content 4</p>
<p>some content 5</p>
<p>some content 6</p>
<p>some content 7</p>
<p>some content 8</p>
<p>some content 9</p>
<p>some content 10</p>
<p>some content 11</p>

use the heights properly, if the total page height is 2000 or 3000, then only you will see the difference

so put some content below the main tag which make the screen really big more then 2000 px or more

When you keep scrolling the some content 1 to 10 will push the pinned item based on the screen or page height

Dickens A S
  • 3,824
  • 2
  • 22
  • 45