Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
CSS Float Question (Strange behaviors found)

Dears,

Below is my simple float program and I also attach a picture of the result. My question is: When the width in class "two" is 300px, the div 2 is moved next to the floated div 1, this is also my expectation. However, when i changed the width in class "two" from 300px to 200px, div 2 is kept under div 1, and div 3 is moved to overlap with div 2 (see the attached picture) Why? enter image description here

<html>
<head>
<style>
.one{
    background: yellow;
    width: 200px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;
    Float: left;
    }

.two {
    background: rgb(55, 0, 255);
    width: 300px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;  
  }

.three {
    background: rgb(255, 0, 76);
    width: 200px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;
   }
 </style>
 </head>
 <body>
    <div class = "one">1</div>
    <div class = "two">2</div>
    <div class = "three">3</div>
 </body>
 </html>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Alright I think I figured it out. The problem lies in the fact that it just looks like as if the second div is below the first. It actually properly overlaps the first div and just leaves the text behind. You can see this if you add opacity or remove the background-color of the first div.

You can add display: flow-root to your second (and third) div to fix this if needed or use 'float: left' on all of them as suggested.

<html>
<head>
 </head>
 <body>
    <div class = "one">1</div>
    <div class = "two">22222222</div>
    <div class = "three">3</div>
 </body>
 </html>
.one{
    background: transparent;
    width: 200px;
    height: 50px;
    text-align: center;
    box-shadow: inset 0 0 10px #000;
    float: left;
    }

.two {
    background: rgb(55, 0, 255);
    width: 200px;
    height: 50px;
    text-align: center;
    box-shadow: inset 0 0 10px #000;
 }

.three {
    background: rgb(255, 0, 76);
    width: 200px;
    height: 50px;
    text-align: center;
    box-shadow: inset 0 0 10px #000;
    }
about 4 years ago · Juan Pablo Isaza Report

0

If you add this style to your blue box;

.two {
  border: 10px solid #0ff;
}

You can see blue box is already under the yellow box. The only thing that is absurd here is; blue box text alignment centered only on the rendered area of the blue box.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!