Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6718249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:56:49+00:00 2026-05-26T08:56:49+00:00

I have simple site, with the classic elements: Container, Header, Content and Footer. The

  • 0

I have simple site, with the classic elements: Container, Header, Content and Footer. The container has a background-color, which covers the whole content of the site (including header, content and footer). For some reason this won’t work with floated elements within the container.

I have found a solution at StackOverflow, but it doesn’t feel right. Solution is to set { display: table; } onto the container id.

The page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
<style>

body
{
  background-color: #999;
  font-family: Tahoma;
  font-size: 12px;
  font-style:normal;
  font-variant:normal;
  font-weight:normal;
  margin: 0px;
  padding: 0px;  
}

h1
{
  color: green;
  font-family:Tahoma;
  font-size: 26px;
  font-weight: bold;
  margin: 5px 0;
  text-indent: 10px;
  width: 100%;
}

#container
{
  background: #FFF;
  margin: 0 auto;
  width: 950px;
  position: relative;
}

#header
{
  position: relative;
  height: 100px;
  width: 950px;
}


#content, #content-ext
{
  float: left;
  margin: 0;
  width: 950px;
}

#nav
{
  float: left;
  padding: 10px 10px 10px 0;
  width: 200px;
}

ul#menu
{
    cursor: pointer;
    display: block;
    list-style: none outside none;
    margin: 0 auto;
    padding: 0;
    text-align: left;
    width: 200px;
}

ul#menu li
{
    margin: 0;
    padding: 0;
}

ul#menu li a
{
    color: #111;
    display: inline-block;
    height: 50px;
    font-size: 18px;
    line-height: 60px;
    margin: 0 auto;
    padding: 0 0 0 10px;
    text-decoration: none;
    width: 100%;
}

#mainImg
{
  background: #111;
  height: 150px;
  float: right;
  margin: 0 0 20px 0;
  width: 710px;   
}

#main-content
{
  float: right;
  width: 710px;
}

#extra
{
  float: left;
  width: 500px;
}

#contact
{
  float: left;
  width: 450px;
}

#footer
{
  color:#999;
  height:20px;
  width:950px;
}

</style>


</head>
<body>
    <div id="container">
    <div id="header">
      <h1>test</h1>
    </div>
        <div id="content">
      <div id="nav">
        <h1>Menu</h1>
        <ul id="menu">
          <li><a href="#">Home</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </div>
      <div id="mainImg"></div>
      <div id="main-content">
        <h1>Welkom</h1>
        <p><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sed arcu arcu, a interdum metus. Aenean vel libero nulla. Nulla facilisi. Maecenas malesuada libero a ante vulputate vestibulum. Cras id neque vitae lectus luctus tempor non non risus. Morbi aliquam porttitor facilisis. Sed pulvinar erat sit amet est auctor tincidunt. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget arcu lorem, non accumsan ipsum. Donec venenatis adipiscing massa, sed molestie augue ullamcorper et.</strong>
        <br/><br/>
        Morbi id eros vitae risus tristique bibendum. Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel, volutpat eget sapien. Proin tempus nunc sit amet ligula viverra hendrerit. Donec tempus tristique risus. Fusce at semper est. Etiam ligula est, varius ut tempus at, laoreet bibendum eros. In hac habitasse platea dictumst.</p>
      </div>
    </div>
    <div id="content-ext">
      <div id="extra">
        <h1>Extra</h1>
        <p>Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel..</p>
      </div>
      <div id="contact">
        <h1>Contact</h1>
        <p>Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel..</p>
      </div>
    </div>
    <div id="footer"></div>
    </div>
</body>
</html>

Does any has a decent solution for using floated elements within a container? And showing the container as overall background?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:56:49+00:00Added an answer on May 26, 2026 at 8:56 am

    Well, there is two classic solutions:

    1. Set “overflow: hidden;” to #container. It will clear floats but have drawback — if you have elements with “position: absolute;” inside container that must be positioned partially outside it, they will be cut by overflow.
    2. Use clearfix hack on #container: http://www.webtoolkit.info/css-clearfix.html it will fix it for you and don’t have this drawbacks but is more complex.

    Not sure is it better then “display: table;” or not, through.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple site, which has a form and an inputbox. I want
Imagine that you have a simple site with only 2 pages: login.aspx and secret.aspx.
We have a rather simple site (minimal JS) with plain html and CSS. It
I have a relatively simple site that I'm working up for an intranet environment.
I have a simple web site ( http://www.kousenit.com/twitterfollowervalue ) that computes a quantity based
Lets say I have a simple ecommerce site that sells 100 different t-shirt designs.
I have a very simple sinatra site that I'm trying to access via ajax
I have a very simple MVC site that is returning a 404 not found
I want to setup a simple site and I don't have any web development
I have a simple PowerShell script that uses WMI to create a web site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.