html - background image can't move up with content -


i developing phone application using jquery mobile. set background image following div: (code copy developer tools after page rendered)

<div data-role="page" id="create_member" data-dom-cache="true" tabindex="0" class="ui-page ui-page-theme-a ui-page-active" style="height: 568px;"><div data-role="content" class="ui-content" role="main">    

css:

#create_member {   background-image: url("../images/common/bg.png");    background-repeat: no-repeat;     background-size: contain;     background-position: top;  } 

bg.png 640x1136 background , fit iphone5 size.

there banner beneath it:

  <div class="banner">          <div class="bannerbg"><img src="skin/images/red_banner.png" \=""> </div>     </div>  

css:

#create_member .banner { margin-top: 34%; }  .bannerbg {  border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; background: #ffe6b8; }  .banner img { width: 97%; margin-top: 5px; } 

however, when try scroll page down, found background fixed, banner can moved not background.

how make banner sits background , when scroll device, move together?

from understand want use background-image css attribute pick image , have sort of banner attached it. see fiddle confirm if behaviour looking for. missing having parent element relative positioning , child element absolute positioning.

why use absolute positioning banner

in absolute positioning model, box explicitly offset respect containing block - w3

why need relative positioning containing block

a relatively positioned box establishes new containing block absolutely positioned descendants. - w3

if didn't have relative positioning, banner instead follow body has containing block. following 2 postioning properties, trick use bottom, left , right @ 0px have stick banner @ bottom of parent, while still scaling in height it's own content.

.banner {     position:relative; }  .bannerbg {     position:absolute;     bottom:0px;     left:0px;     right:0px; } 

not sure if it's looking for. let me know can adjust answer if didn't it! :-)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -