tags:

views:

243

answers:

3

I've been a web developer for really quite some time now, but this is something I've never really done, and my progress so far has used some very complex methods. The following is the layout I want, there are rules to this layout though, as I will explain in a moment.

    ----------------------------------------------------
    |                      HEADER                      |
    ----------------------------------------------------
     ________   _______________________________________
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |        | |                                       |
    |________| |                                       |
               |                                       |
               |                                       |
               |                                       |
               |                                       |
               |                                       |
               |_______________________________________|

The sidebar and the header are static and so is the body, however you can scroll the body. Using the CSS property overflow:scroll on a container for the body section is not an option. The reason being is that it's an ASP.NET application which utilises the maintainpositiononscrollback, meaning that the browser scrollbar - not a contain scrollbar - is what is used to record the x and y position. I have achieved this but using some complex layout techniques which just aren't pretty.

So my HTML looks like the following:

<div id="header">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="#">Telephone</a></li>
    <li><a href="#">My Department</a></li>
    <li><a href="#">My Profile</a></li>
  </ul>
</div>

<div id="sidebar-container">
  <div id="sidebar">
    <!-- sidebar code using ul's and li's -->
  </div>
</div>

<div id="content-top-border"></div>
<div id="content-left-border"></div>

<div id="content-wrap">
  <div id="content">
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
  </div>
</div>

<div id="content-right-border"></div>
<div id="content-bottom-border"></div>
<div id="bottom-block"></div>

So I use all of these divs for a specific reason, so I can absolutely position borders on the content area. The rest of the divs actually block off content by changing the background colour of them so you can't see the content when you scroll.

My CSS file is far too large to be posting on here, but here's the general idea:

div#header {
    height:30px;
    background-color:#d7d7d7;
    position:fixed;
    top:0;
    left:0;
    right:0;
}

div#sidebar {
    position:fixed;
    top:30px;
    left:0;
    overflow:auto;
    bottom:4px;
    width:148px;
    background-color:#d7d7d7;
}

div#sidebar ul {
    border:1px solid #9a9a9a;
    border-bottom:0;
    font-family:Tahoma;
    margin:0 0 0 4px;
    padding:0;
    list-style-type:none;
    font-size:0.75em;
    width:137px;
    clear:both;
    background-color:white;
}

So as you can see from the sidebar, I set a fixed width, make it position:fixed and then set a background. The containing <ul> has a fixed width thus causing a block. When you horizontally scroll the page, the content will be hidden when it hits the sidebar. This creates an effect much like any client-side application.

#content-wrap {
    position: absolute;
    top: 30px;
    bottom: 15px;
    left: 147px;
    right:0;
    background-color:#d7d7d7;
    z-index:-998;
}

#content {
    z-index:-995;
    position:absolute;
    top:0;
    bottom:0;
    right:0;
    left:0;
    padding:10px 10px 20px 10px;
    background-color:#FFF;
    color:#292929;
}

So you can see that the #content has absolute positioning keeping it in that content box. Anything outside of the content box is never displayed even if you scroll horizontally or vertically.

Are there better ways of doing this? It seems a heck-of-a-lot of HTML/CSS to be doing something really quite simple.

EDIT: This layout isn't a problem whatsoever. That part isn't even difficult. What's difficult is maintaining simple HTML/CSS with a complex layout, and by complex, I don't mean something I'm unable to achieve. I have achieved the desired effect already, I'm just looking for a better way of doing it.

EDIT: This is based on business requirements, I don't have a choice :)

+1  A: 

Hey

You could use the markup and css here and adapt it slighty to what you need?

Hope this helps

w4ymo
I can't see how this helps whatsoever? Did you read my post?
Kezzer
i must have misunderstood, my apologies was only trying to help. No need to be so brash about it
w4ymo
My apologies, I didn't mean to seem off key - I don't read what I write sometimes. I fully understand standardised markup as a basis for a web application is a good idea, however, this really is quite a different scenario.
Kezzer
A: 

I'd do this with position:fixed and appropriate margins and width/heights

annakata
Yeah, margins are set already. The layout isn't a problem really, it's just to see if there's another way of hiding overflowing content from the header/sidebar areas.
Kezzer
Hmm, with the right margin/padding/dimensioning your content shouldn't be underflowing liek you describe. I'll load your code up when I get a chance to see where you've gone wrong.
annakata
Basically, when I scroll any content within the content area should not be visible outside of that content area. It works much like a client-side application such as Outlook. Whether you scroll vertically or horizontally only the content area scrolls. It's like using overflow:scroll.
Kezzer
Yeah, it's a fairly common set-up: I'm doing basically the same thing on my own site. It's just tweaking a property or two I suspect, just don't have time to look at it in detail while I'm at work.
annakata
+1  A: 

Fixed position elements are typically a bit of a warning sign for me- by taking things out of the document flow you are losing one of the main benefits of CSS, which is it's flexibility. Again, by mixing px and em measurements you are creating a slightly mixed-up stylesheet jam that doesn't allow for the page to be resized easily.

However the central problem seems to be a question of whether you are barking up the right tree in terms of approach and outcomes. Do you have to be using the maintainpositiononscrollback option from ASP.NET? It wouldn't be too hard to implement a bit of light javascript to create an equivalent effect on an overflowed div. If you are stuck with the asp.net code, do you have to have your text in a small box like that or could you just let the page be as long as the content?

If you have to use the maintainpositionscrollback and you have to have the content in a small box you might be better off using some less standards-friendly code for your markup- perhaps putting the content in an iFrame would give you the behaviour you are looking for. If you're losing most of the benefits of semantic html and css in order to implement the design you want then you're not going to sacrifice much more by taking a different approach to the design.

glenatron
All very valid concerns which I have already raised. Unfortunately it's one of those "we're not changing despite how stupid it is" woes. I honestly wish I could follow your recommendation, but it's just not an option. I wouldn't mind seeing an example of some light javascript for an overflow div
Kezzer
I don't have the code to hand, but the principle would be to put the scroll position of the div into a hidden form field and just retrieve it on load a bit like http://michaelsync.net/2006/06/30/maintain-scroll-position-of-div-using-javascript-aspnet-20 but with less cookies
glenatron