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 8080157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:19:48+00:00 2026-06-05T16:19:48+00:00

I have the following code below however am confused as to why the div

  • 0

I have the following code below however am confused as to why the div element rightnav appears below the div element leftnav if I apply a width property to it. What am I doing wrong or have I misunderstood the use of floats?

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTMl 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />

    <title>DIV example</title>

    <base href="" />

    <link rel="stylesheet" href="" />

    <style type="text/css">

    * {
        margin: 0px;
        padding: 0px;
        font-family: Arial, Verdana, sans-serif;
        font-size: 100%;
    }

    #content {
        width: 700px;
        margin-top: 20px;
        margin-right: auto;
        margin-bottom: 0px;
        margin-left: auto;
    }

    #leftnav {
        float: left;
        width: 200px;
        border-width: 1px;
        border-color: #000000;
        border-style: solid;
    }

    #rightnav {
        border-width: 1px;
        border-color: #000000;
        border-style: solid;
    }


    </style>
</head>
<body>
    <div id="container">
        <div id="content">
            <div id="leftnav">left nav</div>
            <div id="rightnav">right nav</div>
        </div>
    </div>
</body>
</html>

Output

enter image description here

Now if I amend the code as follows by applying the property width to the declaration rightnav, the element appears below leftnav. I thought that it may have to do with the width of the div element content however there is sufficient width with the combination of both div elements i.e. 200px + 200px < 700px

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTMl 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />

    <title>DIV example</title>

    <base href="" />

    <link rel="stylesheet" href="" />

    <style type="text/css">

    * {
        margin: 0px;
        padding: 0px;
        font-family: Arial, Verdana, sans-serif;
        font-size: 100%;
    }

    #content {
        width: 700px;
        margin-top: 20px;
        margin-right: auto;
        margin-bottom: 0px;
        margin-left: auto;
    }

    #leftnav {
        float: left;
        width: 200px;
        border-width: 1px;
        border-color: #000000;
        border-style: solid;
    }

    #rightnav {
        width: 200px;
        border-width: 1px;
        border-color: #000000;
        border-style: solid;
    }


    </style>
</head>
<body>
    <div id="container">
        <div id="content">
            <div id="leftnav">left nav</div>
            <div id="rightnav">right nav</div>
        </div>
    </div>
</body>
</html>

OUTPUT

enter image description here

  • 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-06-05T16:19:50+00:00Added an answer on June 5, 2026 at 4:19 pm

    In your first example, #rightnav is not floating, but it stays at the right because it hasn’t a clear:left; rule. See here: http://jsfiddle.net/5sHdg/

    In your second example, when you specify a width for #rightnav, the browser has a explicit rule about the div’s size, so it renders it as a block element should. But it doesn’t float next to #leftnav because it lacks a float:left; rule. See here: http://jsfiddle.net/Br4Lm/

    So rememeber:

    1. Use float in every div that needs to be positioned besides another one, thus overriding it’s block element appearance.
    2. If you expect to have a div element below divs that re floating, be sure to include clear:both; (left, right, or both);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code below launches a float-in div when my webpage loads, however I
i have the following code below: const char* timeformat = %Y-%m-%d %H:%M:%S; const int
I want to know is below code correct ? I have following code which
I have the following C# code below. Object first = 5; Object second =
i have the following code: <h3> Your Profile </h3> The information below is what
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
I have the following code below: BEGIN TRY BEGIN TRANSACTION -- DO SOMETHIING COMMIT
I am have written the following code below to encode a bitarray into custom
With the following code below I have managed to open an Access.mpd database and
I have the following code below that I'm trying to set a background color.

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.