Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Bootstrap 4, hiding two adjacent columns on mobile stacks them. How can I prevent this?

Hiding a single column on a mobile device using d-none d-md-block works fine, but if I have two adjacent columns I want to hide on mobile, they come out stacked on desktop.

 <table width="80%" class="tabTable table-bordered table-striped table-hover">
   <tr><th class="d-none d-md-block">Col 1</th><th class="d-none d-md-block">Col 2</th><th>Col 3</th></tr>
   <tr><td class="d-none d-md-block">Val 1</td><td class="d-none d-md-block">Val 2</td><td>Val 3</td></tr>
   <tr><td class="d-none d-md-block">Val 1</td><td class="d-none d-md-block">Val 2</td><td>Val 3</td></tr>
</table>

Comes out like

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Adding style="vertical-align:top;" to the <th> and <td> in the first two columns does not seem to fix the issue.

>Solution :

td has by default diplay:table-cell;. d-md-block changes its diplay to block. Block elements take all the avaialbe space.

Since one of the td has diplay:table-cell; and the other two have display:block, they look so.


Use d-md-table-cell instead of d-md-block every where.

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<table width="80%" class="tabTable table-bordered table-striped table-hover">
  <tr>
    <th class="d-none d-md-table-cell">Col 1</th>
    <th class="d-none d-md-table-cell">Col 2</th>
    <th>Col 3</th>
  </tr>
  <tr>
    <td class="d-none d-md-table-cell">Val 1</td>
    <td class="d-none d-md-table-cell">Val 2</td>
    <td>Val 3</td>
  </tr>
  <tr>
    <td class="d-none d-md-table-cell">Val 1</td>
    <td class="d-none d-md-table-cell">Val 2</td>
    <td>Val 3</td>
  </tr>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading