Changing layout in table row using CSS only

Digicom

I have a table using jQuery datatables with some rows in it.

Per this example, the table could look something like this:

https://jsfiddle.net/ef42942g/

enter image description here

I want to use CSS to change the way the table rows are shown so the final result will look something like this: https://jsfiddle.net/hamx5tas/ (please ignore the actual code)

enter image description here

It's very important to keep the basic table structure. I want that the change will be made entirely using CSS (if at all possible).

I have tried various changes to the tr's and td's css but with not much luck.

<table cellspacing="0" cellpadding="0" border="0">
  <thead>
    <tr>
      <th>Thumbnail</th>
      <th>Title</th>
      <th>Price</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
      </td>
      <td>Title 1</td>
      <td>100$</td>
      <td>
        <button>Edit</button>
        <button>Delete</button>
      </td>
    </tr>
    <tr>
      <td>
        <img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
      </td>
      <td>Title 1</td>
      <td>100$</td>
      <td>
        <button>Edit</button>
        <button>Delete</button>
      </td>
    </tr>
    <tr>
      <td>
        <img src="http://www.cmacgm-marcopolo.com/wp-content/uploads/2013/01/vignette-cargo-carnet-pratique-zeebrugge.jpg" width="100">
      </td>
      <td>Title 1</td>
      <td>100$</td>
      <td>
        <button>Edit</button>
        <button>Delete</button>
      </td>
    </tr>
  </tbody>
</table>

I will appreciate any help that can be handed.

Thanks in advance.

Michael Benjamin

You can adjust the layout using CSS flexbox. No changes necessary to the HTML.

CSS

thead > tr { display: none; }

tbody { display: flex; }

tbody > tr {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 5px; 
    border: 1px solid black;
}

tbody > tr > td { 
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 5px;
}

tbody > tr > td img {
    width: 100px;
    height: 65px;
}

tbody > tr > td:last-child {
    flex-direction: row;
}

tbody > tr > td:last-child button {
    margin: 5px;
}

Revised Demo

Note that flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add all the prefixes you need, use Autoprefixer. More browser compatibility details in this answer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Changing the color of a clicked table row using jQuery

From Dev

Razor changing table css

From Dev

hiding part of table using javascript without changing the table layout

From Dev

Changing the css of table rows?

From Dev

HTML CSS Table layout

From Dev

How to I apply a style to only the first row (matching a class) of a table using pure css?

From Dev

Changing visibility of the div element using only CSS

From Dev

CSS table based layout row is not extending 100% width

From Dev

Changing the CSS of Table Row OnClick

From Dev

Changing Table font in CSS

From Dev

highlighting all rowspans within a table row using CSS only

From Dev

Set column width in table with CSS without using <col> or changing the HTML

From Dev

Changing the table row based on a condition

From Dev

Row cannot add dynamically using code to Table Layout in Android

From Dev

Change layout of elements using CSS without changing HTML

From Dev

Responsive CSS table layout make one cell act like a row

From Dev

Change table row layout with css

From Dev

Layout divs either with wrapping or side by side using CSS only

From Dev

How to create masonry layout using css only?

From Dev

Targeting specific class inside table with ID using CSS - Changing ROW background

From Dev

Changing form layout with CSS

From Dev

Changing the CSS of Table Row OnClick

From Dev

Changing Table font in CSS

From Dev

Table CSS Styling (layout)

From Dev

Table breaks after remove row using css

From Dev

CSS only grid layout

From Dev

Table row is higher than specified with CSS (only iPhone)

From Dev

Highlighting a table row when using css hover

From Dev

Changing table row borders query

Related Related

HotTag

Archive