Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda