简体   繁体   中英

How do I make div go under transparent sticky header?

How do I make the background image looks like it's under the header?

https://public.brayzenchase.repl.co/

 * { margin: 0; padding: 0; } header { height: 100px; width: 100%; background-color: rgba(232, 238, 242, 0.3); position: sticky; top: 0; border-bottom: 3px solid #37393A; display: flex; align-items: center; justify-content: center; } section { height: 100vh; width: 100%; background-image: url('https://public.brayzenchase.repl.co/IMG_0290.JPG'); background-repeat: no-repeat; background-size: cover; }
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <header>Sticky Transparent Header</header> <section></section> </body> </html>

Appending the background image to body will do the trick. You are appending it to section , which comes after the header .

 * { margin: 0; padding: 0; } header { height: 100px; width: 100%; background-color: rgba(232, 238, 242, 0.3); position: sticky; top: 0; border-bottom: 3px solid #37393A; display: flex; align-items: center; justify-content: center; } body { height: 100vh; width: 100%; background-image: url('https://public.brayzenchase.repl.co/IMG_0290.JPG'); background-repeat: no-repeat; background-size: cover; }
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <header>Sticky Transparent Header</header> <section></section> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM