2

I may have to alter the structure of DIVs I am using for my webpage layout.

On this page, I have:

<div id="container_slider"></div>
<div id="container_content">
  <div id="main">
    <div id="header"></div>
    <div id="content"></div>
  </div>
</div>

<style>
  #container_slider {position: absolute; top: 0; z-index: 1;}
  #container_content {position: absolute: top: 0; z-index: 10;}
  #main {width: 940px; margin: 0 auto;}
  #header {width: 170px; float: left;}
  #content {width: 760px; float: right;}
</style>

I want #header to display overlaying #container_slider, but I want #content to display vertically beneath #container_slider.

The trouble I have is that the contents of #container_slider is responsive, so the height of #container_slider depends on the browser dimensions.

This means I can't set an accurate padding-top for #content.

Is there a way I can dynamically set #content's padding-top to a value = height(#slider_container) + 10 ?

Or do I need to adjust the way I construct my DIVs?

2 Answers 2

2

You can check height on document ready function by this:

var heightSlider = $('#container_slider').height();

Then apply the same as padding-top for content:

 $('#content').css({ paddingTop : heightSlider + 30 + 'px' });

Demo

Sign up to request clarification or add additional context in comments.

Comments

0

Just an implementation of the above answer that dynamically adjusts for nav bar height.

$( document ).ready(function() {
var topHeight = $('#topNav').height();
var bottomHeight = $('#bottomNav').height();
$('body').css({ paddingTop : topHeight + 5 + 'px' });
$('body').css({ paddingBottom : bottomHeight + 5 + 'px' });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.