Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

328
Vistas
why is this html code not working i.e when I set ancestor color it gets set but when I set ul property to float it does not display ancestor color?

the code contains html code and css code. Here In html I have an ancestor div element with class name navigation and the child I have an unordered list. When I do not set the property to float:right or left it takes the background color of ancestor. however when I set the property of child element to float:right or left the background color is not displayed.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: yellow;
}

.container {}

.navigation {
  background-color: red;
}

ul {
  /* here I am not setting the float property and it is taking the ancestor
   background color */
}

/* CSS changes I made */ 
ul {
  /* here I am setting float property to right */ 
  float: right; 
}
<body>
  <div class="container">
    <div class="logo">
      <img src="https://dummyimage.com/300x100/000/fff">
    </div>
    <button type="button" class="nav-toggler">
                    <span></span>
                </button>
    <nav class="navigation">
      <ul>
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Gallery</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact Us</a></li>
      </ul>
    </nav>
  </div>
</body>

the navigation color in the background gets hidden. Can you please help me why its not displaying the background color red when I change the ul property to float:right

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is because you did not clear your float

Whenever your job is done you need to clear float effect and if you don't the raw will left open and browser can't calculate the height of your element so your element's height will be 0 and therefore you can't see your background

    <nav class="navigation">
    <ul>
       <li class="active"><a href="#">Home</a></li>
       <li><a href="#">Services</a></li>
       <li><a href="#">Gallery</a></li>
       <li><a href="#">About</a></li>
       <li><a href="#">Contact Us</a></li>
     </ul>
     <div class="clear-fix" ></div>
   </nav>

   .clear-fix{
        clear: both;
   } 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda