CSS Troubles

Just starting out with CSS and encountering an issue where the main content and sidebar are not aligning correctly. Any ideas on what could be causing this?

Below is the HTML and CSS being used:

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

<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> <!-- Sidebar -->

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

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

          <div id="content">
            This is where the content goes

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

      <div id="footer">

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

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

Here's 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 {

}

Answer №1

Take a look at the insightful Holy Grail article on A List Apart. This article offers a great technique for creating a 3 column layout.

Avoid the temptation to use tables for your layout - reserve the table tag for actual data tables. Instead, utilize divs, spans, lists, and other elements for layout purposes.

The advantage of a table-less layout is primarily improved accessibility: older browsers or mobile browsers will still render the HTML content even if they cannot display the CSS properly. Div tags may be ignored, but using tables could clutter your design. It's true, you may end up with plenty of divs, but relying on tables for layouting is no longer necessary in today's web development environment!

Furthermore, I recommend steering clear of WYSIWYG tools when starting out. Crafting clean HTML by hand allows for greater control and efficiency in the long run. With practice, writing HTML manually can be faster than using a tool. In my experience, professional designers prefer coding HTML directly in plain text...

Answer №2

The sidebar is currently aligned to the right, while the main content remains unaligned. To address this issue, consider rearranging the markup so that the sidebar appears above the main content. Alternatively, you could also apply a float property to the main content.

Answer №3

Utilize the float:left property for the left div tags and float:right for the ones on the right side. It seems like you may have overlooked including these float properties.

Answer №4

Uncertain about the specific goal you have in mind, but it seems like you might be looking for something along these lines...

To update the CSS class definitions, consider swapping out #menu_bar, #main_content, and #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;
}

Answer №5

There was a need for a div element within the structure, specifically at the final position indicated by

with a CSS property requirement as follows:

clear {

clear: both;

}

Implementing this would address the alignment issue, ensuring that both the sidebar and main content are positioned correctly. Subsequent adjustments can then be made to their widths and margins accordingly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strikethrough feature not specified on the website

Check out this unique website that showcases text with a strikethrough. Interestingly, I couldn't find any mention of it in the CSS or HTML code. Here is a snippet from the code: <div style="width:100%;height:259px;background-image: url('< ...

Is it possible to adjust the fill color of an SVG embedded within an object without directly modifying the SVG file with CSS code?

Is there a method to change the fill color of an SVG on hover within an object tag without inserting CSS code directly into the SVG file? Below is the code snippet: <div class="icon-holder"> <object data="http://useaible.com/wp-content/themes ...

Assigning a Sass variable to an HSL value does not function properly when attempting to utilize it with HSLA

My Sass variable is mapped to an hsl value, but when I try to use it with hsla to add transparency, it doesn't work. This is what I'm trying to do: $white:hsl(100, 100%, 100%); .thing{ color:hsla($white,.9); } When using gulp-sass to build my ...

Unable to show the URL for the background image

https://i.sstatic.net/XcdHF.jpg Encountering an issue in displaying the image, I am unsure about the specific subdirectory to navigate from the css folder to the images folder despite my attempts. background: url('images/home1.jpg') top left no ...

Get the Bootstrap download that includes CSS files rather than the LESS files

What is the reason behind bootstrap switching to only having LESS files instead of the traditional bootstrap.css file? Is there a way to download the bootstrap framework that includes the CSS files instead of just the LESS files? ...

The dilemma of selecting objects in Three.js

Currently, I am developing a small web application that utilizes three.js. However, I have encountered an issue: I created a prototype with my three.js content and everything functions correctly (the canvas size in the prototype matches the browser window ...

Tips for resizing the width automatically within a container?

I am facing an issue with a container that contains 3 DIVS: left sidebar, main content, and a right sidebar. I have made the main content responsive by setting the width to width:calc(100% - 400px); (where 400px is the combined width of the sidebars). Howe ...

Tips for personalizing the appearance of active bootstrap tabs?

I am currently working on creating a website where Bootstrap tabs will display content according to their unique ID when selected. However, I have encountered an issue where the tab selected does not remain active. I am thinking of creating a custom active ...

Using CSS to create clickable areas on an image

Here is an example image: https://i.sstatic.net/EerkN.jpg This image shows a desk with various elements, and I am looking for a way to make parts of the image interactive. For example, clicking on the monitor would take you to a specific link, and click ...

Centering a form on a webpage with Bootstrap: A step-by-step guide

Utilizing twitter-bootstrap for styling, I have implemented a login form and am attempting to center it on the page. Most suggestions on stackoverflow advise placing elements inside the container class, which is what I have done. The requirement is for t ...

Ensure consistent row height on small screens

I've been utilizing the Bootstrap tables from the Fluent Kit framework, but I've noticed that on smaller screens, the text in the cells wraps to a new line instead of expanding to fit the available width, even though it's inside the .table-r ...

Why is my JQuery event delegation failing to function correctly?

Looking for some help with a jQuery issue I'm having! I have a script that adds rows to a table, but the new input fields do not trigger any jQuery events. When I click on the first input, it fills in the number 5. However, when I add a new row and c ...

Looking for a single solution to have my background image in CSS cover the entire screen on both my computer and cell phone

I used the following code in my demo .html file: body{ background-image: url('https://i0.wp.com/www.socialnews.xyz/wp-content/uploads/2020/10/26/5573c6f0bee7ca021f4a8aecbaf6cbeb.jpg?quality=80&zoom=1&ssl=1'); -webkit-backgroun ...

HTML/CSS: Maintain Hover-Over Pop Up Boxes in Position Until Another Element is Hovered Over

Seeking HTML code to maintain a hover-over pop-up box in position on an image map until another section of the image map is hovered over. For example, refer to my code below - when hovering over a country on the map, a pop-up box with information about a ...

What is the best way to position the content area to the right of the menu on my website?

Hey there! I'm currently facing an issue with Bootstrap 4 where my content area is appearing below the vertical navbar instead of next to it on the right side. Any suggestions on how to adjust my code to fix this? Thanks in advance! <div class=&qu ...

Modify the theme color within Luna Admin Template

I'm working on customizing an admin template with a dark background color, but I've been struggling to change it to a light/white color for hours. You can find the template here. I also submitted a question on the sales page, but I haven't ...

Mobile menu malfunction

I am currently troubleshooting an issue with the mobile version of the menu on my website. I am using php in combination with bootstrap, and for the most part, everything seems to be working correctly. However, the problem arises when trying to access the ...

The bootstrap navbar spreads across the entire page, yet it doesn't reach every single page

I'm currently in the process of constructing a website for a restaurant. One particularly strange issue I've encountered is that the navigation bar covers the entire page, but only on specific pages like the cart, login, and register pages. Stran ...

How can I turn off autocomplete in MUI textfields?

Currently, I am working with the latest version of mui. Within my user contact info form, there is a zip code field that I do not want to be auto completed if the value is null. However, despite my efforts, it continues to autocomplete with the email saved ...

Altering an element's visibility from 'none' will trigger its animation to play once again

Take a look at the snippet below and you'll see that the sliding animation plays twice - once when the .addClass statement runs, and again when #test's display is switched to 'initial' (timeouts are in place to help visualize the issue) ...