1

I have a tablular structure (a table with no th) that looks like:

---1--- ---2---

---3--- ---4---

I want it be like this is mobile screens:

---1---

---2---

---3---

---4---

Whatever I do i can't design that. My suggested code:

   <table>
    <tbody style="width: 100%">
    <tr class="row">
        <td class="col-xs12 col-sm-6 display-block">1</td>
        <td class="col-xs12 col-sm-6 display-block">2</td>
    </tr>
    <tr class="row">
        <td class="col-xs12 col-sm-6 display-block">3</td>
        <td class="col-xs12 col-sm-6 display-block">4</td>
    </tr>
    </tbody>
    </table>

always results

1

2

3

4

and without display-block always results

---1--- ---2---

---3--- ---4---

2 Answers2

3

If you use bootstrap you have to set col-xs-12 instead col-xs12 (add -)

See JSFiddle:https://jsfiddle.net/v09bzj89/

  
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  <table>
    <tbody style="width: 100%">
    <tr class="row">
        <td class="col-xs-12 col-sm-6 ">1</td>
        <td class="col-xs-12 col-sm-6 ">2</td>
    </tr>
    <tr class="row">
        <td class="col-xs-12 col-sm-6">3</td>
        <td class="col-xs-12 col-sm-6">4</td>
    </tr>
    </tbody>
    </table>
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47
0

Use media query and add the display: block style in that block only, so that it applies only in a particular resolution.

// This style will be applied only below screen widths 600px
@media screen and (max-width: 600px) {
  .display-block {
       display: block !important;
  }
}

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
  @media screen and (max-width: 600px) {
  .display-block {
   display: block !important;
  }
}
  </style>
</head>
<body>
   <table>
  <tbody style="width: 100%">
     <tr class="row">
        <td class="col-xs12 col-sm-6 display-block">1</td>
        <td class="col-xs12 col-sm-6 display-block">2</td>
     </tr>
     <tr class="row">
        <td class="col-xs12 col-sm-6 display-block">3</td>
        <td class="col-xs12 col-sm-6 display-block">4</td>
     </tr>
  </tbody>
   </table>
</body>
</html>
Nandita Sharma
  • 13,287
  • 2
  • 22
  • 35