Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap table - split one of the row's column in two

I managed to create 'double row' for a table in Bootstrap:

<table class="table table-striped table-bordered">
    <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
    </tr>
    <tr>
        <td>A</td>
        <td>A</td>
        <td>A</td>
    </tr>
    <tr>
        <td rowspan="2">B</td>
        <td>B1</td>
        <td>B1</td>
    </tr>

    <tr>
        <td>B2</td>
        <td>B2</td>
    </tr>
</table>

Ideally I want it to look like this: enter image description here

Playing around with colspan didn't really help, only broke things. I tried to set colspan of every row's first column to 2 and the one of B to 1, and have additional <td> for B1 and B2, didn't work.

like image 917
Amir Avatar asked Sep 02 '15 16:09

Amir


People also ask

How do I split a row into two columns in Bootstrap?

You can use col-md-* class for child element inside the parent row class to split the columns for your need.

How do you split a TD with two lines?

you can put a table inside that table cell, then that inner table you can do whatever you want, like td colspan="2" for the top row, and td td for the bottom row (this reminds me of the ugly days of table layout, but whatever works for you!)


Video Answer


1 Answers

Finally I've got a solution for you :

SNIPPET

.container {
  background-color: #ccc;
}
thead{
  background:#C9E4F4;
}
table,
th,
td {
  text-align: center !important;
  border: 1.5px solid #929292 !important;
}
#text1 {
  background-color: #cac;
}
#text2 {
  background-color: #cca;
}
#navigation {
  background-color: #acc;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered">
  <tr>
    <thead>
      <th colspan="2">1</th>
      <th>2</th>
      <th>3</th>
    </thead>
  </tr>
  <tr>
    <td colspan="2">A</td>
    <td>A</td>
    <td>A</td>
  </tr>
  <tr>
    <td rowspan="2">B</td>
    <td>B1</td>
    <td>B1</td>
    <td>B1</td>
  </tr>
  <tr>
    <td>B2</td>
    <td>B2</td>
    <td>B2</td>
  </tr>
</table>
like image 163
Ramiz Wachtler Avatar answered Oct 18 '22 01:10

Ramiz Wachtler