html - Preserving the appearance of CSS flow while switching position from relative to fixed -


i'm wondering what's best way deal this: have 2 div in document flow (nav + content), positioned relative.

in situations, need give nav fixed position. removes nav flow, content div no longer located below. add content top-margin compensate, have computed because nav doesn't have set height (in example, it's 50% of window height).

any suggestion?

jsfiddle: http://jsfiddle.net/6gkvs/

the best way calculate number , apply somewhere else, javascript, because have find number after dom loaded.

i'm going of (this date) shouldn't using fixed positioning @ without testing touch modernizr, , in case it's "no-touch" use fixed, due less adequate browser support on mobile , touch enabled desktop. try 1 out @ store , you'll see mean. jumpy weird fixed headers everywhere.

the fact divs relative doesn't matter.

the best thing do, run modernizr. spit out no-touch class on html can use style with.

.no-touch nav {     position: fixed;     top: 0; left: 0; } 

then jquery, can along these lines - if using box-sizing: border-box (which suggest) you'll want use '.outerheight()' sure include padding , borders. you'll want fixed header when screen big enough accommodate it.

var windowheight = $(window).height(); var navheight = $('nav').outerheight();  if ( windowheight > 600 ) {    $('nav').addclass('fixed-nav');    $('section').css('margin-top', navheight);  } 

here a fiddle. hope helps. sorry there no way css yet. cool.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -