views:

148

answers:

6
+1  Q: 

Problem with CSS

Am a newbie in CSS and am writting this code and the main content and the sidebar are falling out of place. Anyone know why?

Here is the HTML and CSS used

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;

<html>
  <head>
    <title> WEB HELPDESK</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="styles/polaris.css" type="text/css" />
  </head>
  <body>
    <div id="container">
      <div id="header">
        <p class="banner"> WEB HELP DESK <p>
      </div>

      <div id="pathway">

      </div> <!-- pathway -->

      <div id="main">
        <div id="menu_bar">
          <div class="menu">
            <ul>
              <li> <a href=""> Manufacturers </a> </li>
              <li> <a href=""> Add Manufacturer </a> </li>
              <li> <a href=""> Edit manufacturer </a> </li>
              <li> <a href=""> Delete Manufacturer </a> </li>              
            </ul>
            <ul>
              <li> <a href=""> Asset types </a> </li>
              <li> <a href=""> Add Asset types </a> </li>
              <li> <a href=""> Edit Asset Types </a> </li>
              <li> <a href=""> Delete Asset Types </a> </li>
            </ul>
            <ul>
              <li> <a href=""> Asset Status </a> </li>
              <li> <a href=""> Add Asset Status </a> </li>
              <li> <a href=""> Edit Asset Status </a> </li>
              <li> <a href=""> Delete Asset Status </a> </li>              
            </ul>
            <ul>
              <li> <a href=""> Assets  </a> </li>
              <li> <a href=""> Add Asset  </a> </li>
              <li> <a href=""> Edit Asset  </a> </li>
              <li> <a href=""> Delete Asset  </a> </li>              
            </ul>
          </div>
        </div> <!-- Menu bar -->
        <div id="sidebar">
          sidebar
        </div> <!-- Menu bar -->

        <div id="main_content">
          <div id="errors">

          </div> <!-- Errors -->

          <div id="content">
            content goes here

          </div> <!-- Content -->
          am floating here
        </div>
      </div> <!-- Main -->

      <div id="footer">

      </div> <!-- Footer -->
    </div> <!-- Container-->

  </body> <!-- Body -->
</html>

And the CSS:

body {
  font-family: arial, san serif;
  color: #000000;
}

#container {
  margin: 0em 1.5em 1.5em 1.5em;
  border: 1px solid #46A5E0;
}

#header{
  margin: 0.1em 0em 0.1em 0.1em;
  border: 1px solid #46A5E0;
  width: 99%;
  height: 5em;

}

#header .banner {
  color: #333399;
  text-align: centre;
  font-size: 1.6em;
}

#pathway {

}

#main {
  margin: 0.1em 0.1em 0.1em 0.1em;
  border: 1px solid #000000;
}

#menu_bar {
  margin: 0.1em 0.1em 0.1em 0.1em;
  border: 1px solid #46A5E0;
  width: 13em;
}

#menu_bar .menu {
  font-size: 0.7em;
}

#sidebar {
  margin: 0.1em 0.1em 0.1em 0.1em;
  border: 1px solid #46A5E0;
  float: right;
  width: 13em;
}

#main_content {
  margin: 0.1em 0.1em 0.1em 0.1em;
  border: 1px solid #46A5E0;
  float: right;
}

#errors {

}

#content {

}

#footer {

}
A: 

Your sidebar is floated right; the main content isn't. Try moving the sidebar above the main content in the markup. Alternatively, try specifying a float for the main content as well.

David M
A: 

Try using table .. its the easiest way in your case .. (The code at-least will be understandable) .. There is No problem with your CSS(I mean to say your CSS design-approach is good) its in the positioning you are making mistake ..

Or you start with some (there are open source open-source tools too) web-designer tools .. we call it WYSIWYG (what you see is what you get) tools .. some kind of drag and drop designing ..

Hope it helped ..

infant programmer
melaos
There is not tabular data in this document, so using a table would be wrong.
Vinz
@Vinz, There is no rule that .. we must use table only for tabular data .. Its a good formatting practice .. no need for any more tutorial on it .. I have a good experience in web-designing .. and its my profession ..
infant programmer
It's a bad formatting practice alright! Of course there is no "rule" against it, the web's a free place... But the W3C HTML reference on the table element states "authors should use style sheets to control layout rather than tables".
Vinz
BTW: Thanks for the serial downvote. Is this way of handling criticism the "infant" side of you?
Vinz
may be .. but I don't completely agree with that .. Style-sheet is just like a taste-maker in your dish .. I have experienced it's side-effects in my first design itself .. The lesson was the skeleton (I mean the HTML) of your web-page must be perfect (take care of your alignments first, being dependent on stylesheets for alignment is not good habbit).. Don't take me otherwise .. I don't hate <div> tag .. I advised table because .. the questioner seemed to struggle with div tag .. If he had used <table> then (certainly) wouldn't have come up with this question at all ..
infant programmer
sorry?! I have'nt downvoted your answer ..
infant programmer
The CSS is more than just the taste-maker: It's the whole style of your page. In a perfect world, the HTML would only contain your page's structured data and the CSS all the layout. You are right that the questioner would maybe not have the same problems if he had used tables.. But as I wrote in my post: That would be the EASY way, not the best...
Vinz
TBALES ARE NOT FOR LAYOUTS
Jonny Haynes
Okay, sorry that I suspected it was you then... Just after posting my answer I got like 4 random downvotes on other posts... Div haters I guess ;)
Vinz
Ohk .. I agree with your last-but-one +1 for your comments and answer ..
infant programmer
There's even an SO thread on this question: http://stackoverflow.com/questions/83073/why-not-use-tables-for-layout-in-html
Vinz
ah ! .. ohk thanx for the link .. and thanx for the interaction .. :)
infant programmer
A: 

Go with a float:left for the left resting div tags with float right for the right side div, I suspect you are just missing the float parts.

Sean
A: 

not sure exactly what you're trying to get to, but I suspect something like...

replace the following css class definitions: #menu_bar, #main_content, #footer with

#footer {
 clear:both;
}

#main_content {
 margin: 0.1em 0.1em 0.1em 0.1em;
 border: 1px solid #46A5E0;
 float: left;
}

#menu_bar {
 margin: 0.1em 0.1em 0.1em 0.1em;
 border: 1px solid #46A5E0;
 width: 13em;
 float:left;
}
Paul
A: 

What was required was a div within the at the end indicated as

that would have the following property in CSS

clear {

clear: both;

}

this would solve the positioning problem, it will bring the sidebar and the main_content to the right positions and from here adjustments can be made to the sidebar and main_content in terms of width and margins

Gatura
+3  A: 

Check the Holy Grail article from A List Apart. The article shows the best way to create a 3 column layout.

Don't go the easy path and just use tables for your layout! Use the table tag only for "real tables", for everything else use divs, spans, lists, etc.

The benefit of a table-less layout is mostly that it's more accessible: An older browser, or a mobile browser, will simply ignore the CSS and display only the HTML-contents of the page. Div tags will be ignored, while a table would clutter your layout... It's true, there will be LOTS of divs! But using tables for layouting isn't necessary anymore these days!

Also, personally, I wouldn't start with a WYSIWYG tool. If you want clean HTML you will have to write it yourself. Also, with a little practice, you will write HTML faster by hand than with a tool. All the professional layouters I have worked with write HTML in plain text...

Vinz