html - How Does This CSS Only Parallax Work? -
i've created parallax scrolling effect using css. i'm struggling understand why it's working. can explain.
html
<div class="image"></div> <section class="content"> <p>text goes here</p> </section> css
.image { background: url('http://s28.postimg.org/v6mfcxbyl/galaxy.jpg') no-repeat fixed; background-position: center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; min-height: 500px; } .content { width: 100%; max-width: 750px; margin: 0 auto; background: #fff; box-sizing: border-box; -moz-box-sizing: border-box; position: relative; z-index: 2; background: #fff; width: 100%; } it looks has setting background fixed on image div.
here's working fiddle http://jsfiddle.net/pajnr/
position:fixed , background-attachment:fixed mean element not move in relation viewport. scroll, title (position:fixed) , background image (background-attachment:fixed) not move. thing move text (.content) doesn't have position:fixed.
when text crosses on title, has higher z-index (and position:relative z-index not ignored) hides whatever underneath (the title).
Comments
Post a Comment