user image

Dev-Mo
Published in : 2022-02-10

Sticky header goes behind the Images

HTML & CSS

My aim here is to make a sticky header that sticks to its original place in the window despite scrolling. The thing is whenever I give it position sticky it moves behind the image! or maybe behind its containing div. I replaced position sticky with position fixed and nothing changed. Still is the same thing.

* { box-sizing: border-box; margin: 0; padding: 0;}body { background-repeat: no-repeat; background-attachment: fixed; background-size: cover; /* padding-top: 100px; */}.section1 { /* position: sticky; */ display: flex; justify-content: center; align-items: center; overflow: hidden; position: relative; text-align: center; color: blueviolet;}.section1 img { /* position: sticky; */ flex-shrink: 0; min-width: 100%; min-height: 100%; position: relative; text-align: center;}.centered { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);}li,a,button { font-family: "Montserrat", sans-serif; font-weight: 500; font-size: 16px; color: #edf0f1;}header { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 30px 10%; background-color: #24252a;}.header_logo { cursor: pointer; margin-left: -70px;}.nav_links { list-style-type: none;}.nav_links li { display: inline-block; padding: 0px 20px;}.nav_links li a { transition: all 0.3s ease 0s;}.nav_links li a:hover { color: #0088a9;}button { padding: 9px 25px; background-color: rgba(0, 139, 169, 1); border: none; border-radius: 50px; cursor: pointer; transition: all 0.3s ease 0s;}button:hover { background-color

Comments

Mohammed Bal'awi Date : 2022-02-11

Best answers

1

Best answers

1

Hello Dev-Mo,

You need to add this:

header {

z-index: 999;

}

Any number from 1 to 9999 will be fine

The z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Hope this solve your problem.

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Is OOCSS still a good CSS architecture in 2022?
Publish date: 2022-02-08 | Comments: 2

Tag: HTML & CSS

Invalid CSS after : expected expression was - SASS error
Publish date: 2022-02-13 | Comments: 1

Tag: HTML & CSS

How to align an Textarea in the middle of the webpage
Publish date: 2022-02-27 | Comments: 1

Tag: HTML & CSS

Can't move the background-image code from CSS file to HTML file.
Publish date: 2022-02-13 | Comments: 2

Tag: HTML & CSS

How do custamize my button to give it a bubble look using CSS?
Publish date: 2022-03-04 | Comments: 0

Tag: HTML & CSS

What is the need for using (for) attr in the label of an input tag?
Publish date: 2022-02-11 | Comments: 2

Tag: HTML & CSS

Do I have to upload the sass files or just the CSS file?
Publish date: 2022-02-11 | Comments: 1

Tag: HTML & CSS

Multiple classes in :not() function in CSS
Publish date: 2022-07-25 | Comments: 2

Tag: HTML & CSS