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

  • SEARCH
  • Home
  • 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 6897817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:13:03+00:00 2026-05-27T07:13:03+00:00

<html> <head> <style type=text/css> div { background-color:#ccc; } </style> </head> <body> <div> <div style=float:

  • 0
<html>
<head>
<style type="text/css">
div
{
background-color:#ccc;
}
</style>
</head>

<body>
<div>
<div style="float: left;">This is a text inside a div element.</div>
<div style="float: right;">We are still in the div element.</div>
</div>

</body>
</html>

Why isnt the background color showing up in between those 2 divs?
Output after running this page

  • 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-27T07:13:03+00:00Added an answer on May 27, 2026 at 7:13 am

    When you float elements you should provide the width of the floated elements. Otherwise you may encounter unexpected behaviors accross different browsers.

    Check this tutorial, there is good info on floating in css. [link is dead]

    Basically, if you provide an overflow:hidden; to the container div and provide width to the floated elements, your problem will be solved.

    <div style="overflow: hidden;">
      <div style="float:left; width: 300px;">Some text</div>
      <div style="float:right; width: 300px;">Some text</div>
    </div>
    

    Similarly, you can add another div wherever you want to normalize the flow ike this:

    <div>
      <div style="float:left; width: 300px;">Some text</div>
      <div style="float:right; width: 300px;">Some text</div>
      <div style="clear:both;"></div>
      <div>This div will be at the same place 
           as if the previous elements are not floated</div>
    </div>
    

    Both will work 🙂

    EDIT

    Another method which I use frequently in these days is to float the first element and set a margin-left to the following element. For instance:

    <div>
        <div style="float: left; width: 300px;">Some text</div>
        <div style="margin-left: 300px;">Some text</div>
        <div style="clear: both;"></div>
    </div>
    

    The advantage of this method is that the following element (the second div in this case) does not need a fixed width. Plus, you may skip the third div (clear: both;). It’s optional. I just add it in case that the floated div is longer in height than the second div since if you don’t add it the parent div will always get the height of the second div.

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

Sidebar

Related Questions

<html> <head> <style type=text/css rel=stylesheet> * {margin:0;padding:0;} div#box {background-color:green;width:1000px;} /* #box {position:absolute;top:0;right:0;} */ /*
I have the following code <html> <head> <title>Test</title> <style type=text/css> <!-- body,td,th { color:
<html> <head> <style type=text/css> div { border:1px solid #000; min-width: 50%; } </style> </head>
I have this code <html> <head> <style type=text/css> .frame {width: 50em; border: 1px solid
I have a list like this: <html> <head> <link type=text/css rel=stylesheet href=testli.css> </head> <body>
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
<!doctype html> <html> <head> <title>JQuery Cycle Plugin - Example Slideshow</title> <style type=text/css> .slideshow {
Here is a complete test case: <!DOCTYPE html> <html> <head> <title>test</title> <style type=text/css> html,
I'm trying to generate a dynamic table using CSS: <html> <head> <style> div.el1, div.el2
my code is: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <style

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.