Search code examples
colorsbootstrap-5darkmode

Bad color in table. Bootstrap 5.2.3


I have no practice as a bootstrap user. I have a table. when i set dark mode in browser then the color of text is wrong (black on black background). What am I doing wrong?

(fg-color is only bad in table when class="table" added)

<!doctype html>

<html lang="pl">
    <head>
        <meta charset="utf-8">

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>

        <link rel="stylesheet" type="text/css" href="/static/admin/css/base.css">
        <link rel="stylesheet" type="text/css" href="/static/admin/css/nav_sidebar.css">
        <link rel="stylesheet" type="text/css" href="/static/admin/css/dashboard.css">

        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">

        <link rel="stylesheet" type="text/css" href="/static/admin/css/responsive.css">
    </head>

    <body>

        <table class="table table-responsive table-bordered">
            <thead>
                <tr>
                    <th class="text-center" scope="col">Name</th>
                    <th class="text-center" scope="col">Price</th>
                    <th class="text-center" scope="col">Qnt</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>product 1</td>  
                    <td class="text-end">12,48</td>
                    <td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
                </tr>
                <tr>
                    <td>product 2</td>  
                    <td class="text-end">12,48</td>
                    <td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
                </tr>
                <tr>
                    <td>product 3</td>  
                    <td class="text-end">12,48</td>
                    <td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
                </tr>
            </tbody>
        </table>

    </body>
</html>

I tried using a div container and some classes but it doesn't change anything.


Solution

  • For styling depending on browser based color mode/theme, you can use the prefers-color-scheme media query as it is used to detect whether the user has requested a light or dark theme based on operating system setting or user agent (browser in this case) settings.

    You can set the color for the table using this query:

    @media (prefers-color-scheme: dark) {
      your-selector {
        color: white;
      }
    }
    

    Reference - MDN