Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

kendall strautman
kendall strautman
7,114 Points

Trying to get Header & Footer over background slider

Hi!

I'm attempting to make a simple portfolio page-style site with a full-screen background slider and the header / footer elements over the images.

The header / footer currently seem to be block level with white space separating them from the image. I'm not quite sure how to change them or the slider div to have it so the contents inside header / footer overlay the sliding background images. I'm assuming something with the z-index but kind of lost! Any help would be appreciated!

https://codepen.io/kstraut/pen/xWVzeM

2 Answers

Austin Whipple
Austin Whipple
29,725 Points

I think the best way to do this while not fussing with the HTML too much to leave options open for other page layouts would be to focus on making the slider full screen and use absolute positioning. Try something like:

.slider {
  width: 100vw;
  height: 100vh;
  margin: 0;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
}

You'll notice I set both a height and width now that I've switched it to position: absolute;. You'll also need to declare top and left values to make sure it sticks to the correct part of the page. Adding z-index: -1 will keep it behind all other content.

Because switching to position: absolute; takes the .slider element out of the normal document flow, you'll probably need to tweak your flexbox properties and height properties on body to make sure your header and footer stay at the top and bottom of the page.

kendall strautman
kendall strautman
7,114 Points

Thanks Austin! That behaves just as you've described. Appreciate it!

jared eiseman
jared eiseman
29,023 Points

My suggestion would be to experiment with either floats or absolute/fixed positioning. The latter would negate your use of flex box, but will probably get you you're desired effect with less hassle.

kendall strautman
kendall strautman
7,114 Points

Thank you for the feedback! I figured I was going to have to mess around with / do away with the flexbox positioning.