Dan Cundy
Dan Cundy

Reputation: 2849

How to stop an absolutely positioned div from stacking over/under a fixed div?

Problem

I have a fixed header and a absolutely positioned content div. They are both positioned using a top value, and sit fine until the page height is of a height that requires the scrollbar to appear.

The absolutely positioned div then moves with the page and stacks under the header.

NB: The div absolutely positioned div 'photoframe' must remain able to scroll horizontally.

I've made a JsFiddle to better demonstrate what i'm trying to explain.

JsFiddle of problem

My CSS

@charset "utf-8";
/* CSS Document */


/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}

*, :before, :after {
    -ms-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box
}
body {
    line-height: 1;

}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/*End of CSS reset*/


a:link {
    color: #FFF;
    text-decoration: none;
}      /* unvisited link */
a:visited {
    color: #FFF;
    text-decoration: none;
}  /* visited link */
a:hover {
    color: #FFF;
    text-decoration: none;
}  /* mouse over link */
a:active {
    color: #030303;
    text-decoration: none;
    font-size: 100%;
}  /* selected link */

html{
    height:100%;

}
body{
    background-color:#424242;
    height:100%;


}

#spacer
{
    height:400px
}



#headerWrapper {
    position: fixed;
    display: inline-block;
    width: 100%;
    height:400px auto;
    z-index: 999;
    top: 0;
}


#headerWrapper #header{
    position: fixed;
    display: inline-block;
    width: 100%;
    height: 200px;
    z-index: 999;
    top: 0;


}
#headerWrapper #header #title{
    position: fixed;
    font-size: 3em;
    color: #FFF;
    margin-top: 30px;
    margin-left: 30px;
    margin-bottom: 10px;
    top: 0px;
}

#headerWrapper #header #tagline{
    position: fixed;
    font-size: 2em;
    color: #d3701e;
    margin-left: 30px;
    top: 90px;
}

#tabsContainer {
    padding: 0;
    margin-left:18px;
    position: fixed;
    top: 120px;
    font-size: 14px;
    line-height: 18px;
    font-family: "swiss", "Arial", sans-serif;
    font-weight: 400;
    text-transform: uppercase;
    cursor: default;
    white-space:nowrap;
}
#tabsContainer ul {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size:24px;
}
#tabsContainer ul li {
    display: inline;
    margin: 0px;
    display: block;
    height: 50px;
    text-align: center;
    line-height: 30px;
    font-size:24px;
}
#tabsContainer ul li a {
    height: 33px;
    display: block;
    float: left;
    padding: 17px 15px 0 15px;
    font: bold 12px Arial;
    color: #FFF;
    text-decoration: none;
    font-size:24px;
}
#tabsContainer ul li a:hover {
    color: #d3701e;
    height: 50px;
    font-size: 24px;
}
#tabsContainer ul li #active a {
    color: #d3701e;
    background: url(images/navigation-hover.png) repeat-x left top;
    font-size:24px;
}

.tab{
float: left;    
font-size:24px;
}

.tab.one
{
    width:220px;
    font-size:24px;

}


/*#photoframeContainer{

    padding-top: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 20px;
    padding-bottom: 20px;
    position: absolute;
    bottom:0px;

}*/

#photoframe {
    position: absolute;
    padding: 0 25px 0 25px;
    height: 600px;
    top: 242px;
    overflow: visible;
    white-space: nowrap;
    left: 0px;


}
#photoframe .imageContainer {
    height: 100%;
    margin: 0 5px 0 5px;
    display: inline-block;
    position: relative;
    overflow: hidden
    }



#photoframe .imageContainer img {
    height: 100%;
    padding: 0;
    margin: 0;
    z-index: 1

}


.upload
{
    float: left;
    vertical-align: baseline;
}

My HTML

<body>
<div id="headerWrapper">
<div id="header">
  <div id="title">
    <h1>Bass Clef Photography</h1>
  </div>
  <div id="tagline">Passion 4 Live Music & Passion 4 Photography</div>
  <div id="tabsContainer">
    <div class='tab zero'>
      <ul>
        <li><a href="BassClef.html">Home</a></li>
      </ul>
    </div>
    <div class='tab one'>
      <ul>
        <li><a href="#">Music Gallery</a></li>
      </ul>
    </div>
    <div class='tab two'>
      <ul>
        <li><a href="#">About</a></li>
      </ul>
    </div>
    <div class='tab three'>
      <ul>
        <li><a href="#">Clients</a></li>
      </ul>
    </div>
    <div class='tab four'>
      <ul>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
    <div class='tab five'>
      <ul>
        <li><a href="members.php">Members</a></li>
      </ul>
    </div>
  </div>
</div>
</div>
<div id="spacer"></div>
<div id="photoframeContainer">
  <div id="photoframe">
    <div class="imageContainer"><img class="resize" src="uploads/picture02.jpg" alt=""></div>
    <div class="imageContainer"><img class="resize" src="uploads/picture03.jpg" alt=""></div>
    <div class="imageContainer"><img class="resize" src="uploads/picture04.jpg" alt=""></div>
    <div class="imageContainer"><img class="resize" src="uploads/picture05.jpg" alt=""></div>
    <div class="imageContainer"> <img class="resize" src="uploads/picture06.jpg" alt=""></div>
    <div class="imageContainer"><img class="resize" src="uploads/picture07.jpg" alt=""></div>
    <div class="imageContainer"><img class="resize" src="uploads/picture08.jpg" alt=""></div>
  </div>
</div>
</body>

Upvotes: 0

Views: 113

Answers (2)

Matthcw
Matthcw

Reputation: 121

Don't penalize me if I'm wrong but, If i understand correctly, you just don't want that vertical scroll bar, so just add

overflow-y:hidden; the body class.

Fiddle

Upvotes: 0

user2246364
user2246364

Reputation:

Given the situation you have two good options and one bad one. The first is to make everything static positioning and give a set width to the container of the images and use overflow:auto on the photo container. That will provide a scroll bar for the div itself like the ones used in stack overflow for codeblocks and such (see your code above). Otherwise, I highly recommend using a javascript or jquery slider. Way easier to implement and you won't have to fight with css every time you add a little content to the page.

The bad option is to lose the spacer and the absolute positioning on the #photoframe element and then add padding-top:242px to #photoframe like so:

#photoframe {
position: static;
padding: 0 25px 0 25px;
    padding-top:242px;
height: 600px;
overflow: visible;
white-space: nowrap;

}

Here is an example. The reason this is a bad option is that you will still have to fight with css if you every have to add menu items or content elsewhere on the page. Fixed positioning really is a nightmare in most cases and mobile/tablet devices do not handle it well at all.

Upvotes: 1

Related Questions