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

195
Vistas
Change the background colour of the whole line

I want to realise the sidebar of a normal editor: when we hover on one filename, the whole line changes to a darker background colour.

However, given the filenames are listed by <ul>, the following code only changes the background colour for <li>, does anyone know how to change the background colour for the whole line where the hover is?

JSBin

.sidebar {
  width: 102px;
  background-color: #f3f3f3
}

li:hover {
  background-color: #cccedb
}
<div class="sidebar">
  <ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
  </ul>
</div>

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Actually the whole line is changed. The problem is the default padding on the ul element, if you remove that you can see what happens. You now have to add list-style-position: inside; to keep the bullets inside if you need. You can also add padding-left: 20px; to the li element to get in the same position like when you had padding on ul. See the snippet below please:

.sidebar {
  width: 102px;
  background-color: #f3f3f3;
}
li{
  padding-left: 20px;
}
li:hover {
  background-color: #cccedb;
}
ul{
  padding: 0;
  list-style-position: inside;
}
<div class="sidebar">
  <ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
  </ul>
</div>

over 4 years ago · Santiago Trujillo Denunciar

0

Try,

.sidebar ul{
  padding: 0;
  margin: 0;
  list-style: none;
 }
 .sidebar ul li{
  padding: 5px;
 }
over 4 years ago · Santiago Trujillo Denunciar

0

The issue is with the bulletin and padding.

add this to ul

list-style-type:none;
padding:0px;

.sidebar {
  width: 102px;
  background-color: #f3f3f3
}
ul{
  list-style-type:none;
  padding:0px;
}
li:hover {
  background-color: #cccedb
}
<div class="sidebar">
  <ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
  </ul>
</div>

over 4 years ago · Santiago Trujillo 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