- This topic is empty.
June 5, 2014 at 4:06 pm #172012
I’m learning how to code and give myself challenges to complete.
Currently, I’m trying to have text disappear behind a transparent header when scrolling down the page. The only solution I’ve found so far, is to give the content an overflow: auto and add top, bottom, and paddings to contain it in a box.
This solution does not work so well. The page will not scroll if the mouse is not in the “content with overflow” area. Also, the scrollbar is restricted only to the content area; so it does not scroll to the very top of the page.
What are some other approaches to achieve this effect.
Here’s a jsfiddle to get an idea of what I’m talking about. http://jsfiddle.net/claireC/6bAW5/4/June 5, 2014 at 5:20 pm #172018
I’m trying to have text disappear behind a transparent header when scrolling down the page
You should try messing with positions. If you give your header a position fixed, it will stay where it is no matter what.
Chris put together a video to give you the basics: https://css-tricks.com/video-screencasts/110-quick-overview-of-css-position-values/
Try that out, if you get stuck again let us know.June 5, 2014 at 5:30 pm #172020
The header is fixed. I have no problems with the position of the header. If you try scrolling while the mouse is on the header, the content will not scroll.
I would like the main content/text to scroll with the mouse anywhere on the page.June 5, 2014 at 5:39 pm #172021
I forked your fiddle on to codepen and made some changes.
http://codepen.io/drainpip/pen/vEFuK (fiddle messed up)
The problem why it wasn’t scrolling was because you were using overflow. Overflow is designed to be its own thing inside a page.June 5, 2014 at 5:56 pm #172022__Participant
If you’re okay with the header being “not really” transparent, then you can simply give it the same background color (or image, in this case) as the rest of the webpage. Get rid of
overflow, and you’re done.June 5, 2014 at 9:26 pm #172033
I thought of giving the header an ing as well, but thought it might be too big of a file size to load both images.June 5, 2014 at 9:42 pm #172034__Participant
thought it might be too big of a file size to load both images.
Just one image. : )June 9, 2014 at 9:46 am #172239
I am seeing two images. One for the body of the page and another for the header.June 9, 2014 at 10:20 am #172240AtelierbramParticipant
They are one and the same image, … like the effect … My fork of shaneisme’s forkJune 9, 2014 at 10:44 am #172241
My example was simply to get your mind moving in the right direction, as I tend to do. Since you said you’re new, I’ll elaborate a little bit on why what @Atelierbram did was awesome (Aside from giving you exactly what you originally wanted!).
You could technically get away with making the page with two images, at first glance that might actually make sense from a stitching together a static image into a website kind of way. But what that causes is two trips to the server and back to the client instead of one. You might also think that this is a trivial thing, but imagine if your page was viewed a few thousand times… tens of thousands…
The browser looks at the code, hey I need this image, server replies back here’s your image, browser doesn’t even thank the server (he’s an ass) and starts to render – oh wait, I need another image, server replies back (thanklessly) here’s your image and browser renders… etc…
In our new example, the browser looks at the code and gets the image, then sees the same image needed again so it pulls it from its session cache and renders it again in fraction of the time AND without the server needing to find the image and send it over the net again.
With a little CSS imagination you can solve problems like this, and the returns compound as the complexity of your sites increases. Thinking about these little things can help save precious milliseconds, and we should all know a millisecond is a lifetime in our game :)June 9, 2014 at 5:08 pm #172265
- The forum ‘CSS’ is closed to new topics and replies.