Tabla Bootstrap rayas: ¿Cómo cambio el color de fondo de la raya?


Con la clase Bootstrap table-striped, cada dos filas de mi tabla tiene un color de fondo igual a #F9F9F9. ¿Cómo puedo cambiar este color?

Author: UnderDog, 2013-12-29

8 answers

.table-striped > tbody > tr:nth-child(2n+1) > td, .table-striped > tbody > tr:nth-child(2n+1) > th {
   background-color: red;
}

Cambie esta línea en bootstrap.css o puedes usar (impar) o (par) en lugar de (2n+1)

 90
Author: Florin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-11 22:05:54

Agregue el siguiente estilo CSS después de cargar Bootstrap:

.table-striped>tbody>tr:nth-child(odd)>td, 
.table-striped>tbody>tr:nth-child(odd)>th {
   background-color: red; // Choose your own color here
 }
 109
Author: kyriakos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-24 19:40:55

Tiene dos opciones, o bien sobrescribe los estilos con una hoja de estilos personalizada, o edita el archivo css principal de bootstrap. Prefiero el primero.

Sus estilos personalizados deben vincularse después de bootstrap.

<link rel="stylesheet" src="bootstrap.css">
<link rel="stylesheet" src="custom.css">
{[3] {} En[2]}
.table-striped>tr:nth-child(odd){
   background-color:red;
}
 11
Author: Eisa Adil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-29 12:39:45

Si está usando Bootstrap 3, puede usar el método de Florin, o usar un archivo CSS personalizado.

Si usa Bootstrap less source en lugar de archivos css procesados, puede cambiarlo directamente en bootstrap/less/variables.less.

Encuentra algo como:

//** Background color used for `.table-striped`.
@table-bg-accent:               #f9f9f9;
 8
Author: Lucas S.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-18 13:31:53

Encontré este patrón de tablero de ajedrez (como un subconjunto de la franja de cebra) para ser una forma agradable de mostrar una tabla de dos columnas. Esto se escribe usando MENOS CSS, y las claves de todos los colores fuera del color base.

@base-color: #0000ff;
@row-color: lighten(@base-color, 40%);    
@other-row: darken(@row-color, 10%);

tbody {
    td:nth-child(odd) { width: 45%; }
    tr:nth-child(odd) > td:nth-child(odd) {
        background: darken(@row-color, 0%); }
    tr:nth-child(odd) > td:nth-child(even) {
        background: darken(@row-color, 7%); }
    tr:nth-child(even) > td:nth-child(odd) {
        background: darken(@other-row, 0%); }
    tr:nth-child(even) > td:nth-child(even) {
        background: darken(@other-row, 7%); }
}

Tenga en cuenta que he eliminado el .table-striped, pero no parece importar.

Parece: introduzca la descripción de la imagen aquí

 2
Author: John Lehmann,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-30 13:25:22

No personalices tu CSS de bootstrap editando directamente el archivo CSS de bootstrap.En su lugar, sugiero copiar y pegar CSS de bootstrap y guardarlos en una carpeta CSS diferente y allí puede personalizar o editar estilos adecuados a sus necesidades.

 2
Author: rai,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-01 14:45:14

Si realmente desea invertir los colores, debe agregar una regla que haga que las filas "impares" sean blancas, así como que las filas "pares" sean del color que desee.

 0
Author: PhPGuy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-13 22:45:42
.table-striped>tbody>tr:nth-child(odd)>td,
.table-striped>tbody>tr:nth-child(odd)>th {
  background-color: #e08283;
  color: white;
}
.table-striped>tbody>tr:nth-child(even)>td,
.table-striped>tbody>tr:nth-child(even)>th {
  background-color: #ECEFF1;
  color: white;
}

Use 'par' para cambiar el color de las filas pares y use 'impar' para cambiar el color de las filas impares.

 0
Author: sammani anuththara,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-04 07:12:34