Search code examples
cssbootstrap-4css-print

How do I make table border black on bootstrap for print


I want to print my page where there's table in it. When i print it it always change to bootstrap default color. I'm using ctrl+p / cmd+p for printing. I'm using bootstrap 4 and laravel 5.7

i've tried to use !important; still not working

My CSS

<style media="screen">
@media print{
  .table thead tr td,.table tbody tr td {
     border: 1px solid #000000!important;
  }
}
</style>

My Table

<table class="col-12 table table-bordered table-sm" >
    <thead class="thead-light">
      <tr>
        <th>Description</th>
        <th>Quantity</th>
        <th>Unit Price (IDR)</th>
        <th>Amount (IDR)</th>
      </tr>
    </thead>
    @php
      $total=0;
    @endphp
    @foreach($ra->sale->details as $items)
      <tr>
        <td>{{ $items->good->name }}</td>
        <td>{{ $items->qty }} pcs</td>
        <td>{{ number_format($items->units,0,',','.') }}</td>
        <td>{{ number_format($items->total,0,',','.') }}</td>
      </tr>
      @php
        $total += $items->total;
      @endphp
    @endforeach
</table>

Solution

  • <style media="print"> .table thead tbody tfoot tr td { border: 1px solid #000000!important; } </style>

    EDIT 2: (Add .thead-light selector)

    <style media="print">
      .thead-light {
         border: 1px solid #000000!important;
      }
    </style>
    

    might be able to remove !important if your selector is specific enough:

    .table .thead-light {
       border: 1px solid #000000;
    }
    

    or

    .table .thead-light tbody tfoot tr td {
        border: 1px solid #000000;
    }