In an HTML table, I’d like the 2nd and 3rd cell to be one above each other, as well as the the 4th and 5th, but the first cell must occupy the whole height of the row.
How to achieve this using CSS (I can’t change the html markup)?
table.shop_table_responsive tbody tr.cart_item td.product-name,
table.shop_table_responsive tbody tr.cart_item td.product-quantity,
table.shop_table_responsive tbody tr.cart_item td.product-subtotal,
table.shop_table_responsive tbody tr.cart_item td.product-remove {
display: block;
}
table.shop_table_responsive tbody tr.cart_item td.product-thumbnail {
max-width: 92px;
}
table.shop_table_responsive tbody tr.cart_item td.product-name {
min-width: 170px;
}
<table class="shop_table_responsive">
<tbody>
<tr class="woocommerce-cart-form__cart-item cart_item">
<td class="product-thumbnail">
<a href="https://staging.mysite.com/fr/eshop/henleys-fr/henley-harri-stone/">
<img width="324" height="324" src="https://staging.mysite.com/wp-content/uploads/harri-stone-mysite-692X692-01-324x324.jpg">
</a>
</td>
<td class="product-name" data-title="Produit" style="
width: 150px;
display: block;
">
<div class="cart_product_name"><a href="https://staging.mysite.com/fr/"><span class="cat_product_name_word1">Henley</span> <span class="cat_product_name_word2">Harri</span></a></div>
<div class="cart_product_color"><a href="https://staging.mysite.com/fr"> Stone</a></div>
</td>
<td class="product-quantity" data-title="Quantité">
<div class="quantity wbu-quantity" dir="ltr">
<a href="">-</a>
<label class="screen-reader-text" for="qty_prod_34745_var_34763">quantité de Henley Harri - Stone</label>
<input type="number">
<a href="">+</a>
</div>
</td>
<td class="product-subtotal" data-title="Sous-total" style="
clear: both;
">
<span class="woocommerce-Price-amount amount">70<span class="woocommerce-Price-currencySymbol"> EUR</span></span>
</td>
<td class="product-remove">
<a href="www.google.com">×</a>
</td>
</tr>
</tbody>
</table>
I know I can use display: block;
on 2, 3, 4 and 5. But how to be sure that 4 is at the top ?
2
Answers
ok this is exaclty what I needed, for those interested, you can achieve it this way, using
flexbox
, setting the height of the row, and usingflex-direction: column
andflex-wrap: wrap;
as follows:To do what you want you need to change the
display
of the table row. You can use either flex or grid for this. Below I have demonstrated using grid, with fixed widths of 33% for the columns, but changing this to "322px auto auto" will allow the thumbnail to be the correct width and the other columns to adjust automagically. By using Grid I have specified where I want the various cells to appear by using thegrid-xxx-start/end
properties.For additional information, I recommend A Complete Guide to CSS Grid