Bootstrap print CSS removes background color

后端 未结 7 1587
[愿得一人]
[愿得一人] 2020-11-28 12:47

When I use bootstrap, it removes the background color from everthing when I try to print my page. Almost everything on my website is using bootstrap classes so I want to avo

7条回答
  •  天涯浪人
    2020-11-28 13:15

    Despite !important usage being generally frowned upon, this is the offending code in bootstrap.css

    .table td,
    .table th {
        background-color: #fff !important;
    }
    

    Let's assume you are trying to style the following HTML:

    Name School Height Weight

    To override this CSS, place the following (more specific) rule in your stylesheet:

    @media print {
        table tr.highlighted > th {
            background-color: rgba(247, 202, 24, 0.3) !important;
        }
    }
    

    This works because the rule is more specific than the bootstrap default.

提交回复
热议问题