<div class="container">
<table>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Product</th>
<th scope="col">Ingredient</th>
<th scope="col">Price</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="index">1</td>
<td class="product">Apple Juice</td>
<td class="ingredient">Apple, Sugar, Water</td>
<td class="price">$ 100</td>
<td class="add-btn">
<button type="button">Add</button>
</td>
</tr>
<tr>
<td class="index">2</td>
<td class="product">Milk Tea</td>
<td class="ingredient">Fresh Milk, Darjeeling</td>
<td class="price">$ 85</td>
<td class="add-btn">
<button type="button">Add</button>
</td>
</tr>
<tr>
<td class="index">3</td>
<td class="product">Honey Lemon Sparkling Water</td>
<td class="ingredient">Honey, Lemon, Sparkling Water</td>
<td class="price">$ 120</td>
<td class="add-btn">
<button type="button">Add</button>
</td>
</tr>
</tbody>
</table>
</div>
*, *:before, *:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container {
margin: 1rem;
}
table {
width: 1000px;
max-width: 100%;
margin: 0 auto;
white-space: nowrap;
border-spacing: 5px;
}
thead > tr {
background-color: #5B9BD5;
color: white;
}
th, td {
padding: 0.75rem 0.5rem;
text-align: center;
vertical-align: middle;
}
th {
border-radius: 0.25rem;
}
td {
border-bottom: 1px solid rgba(0,0,0,0.75);
}
.product {
color: #5B9BD5;
font-weight: bold;
}
.price {
font-weight: bold;
}
button {
padding: 0.25rem 1.25rem;
font-size: 1rem;
border-radius: 1rem;
border: 2px solid #BF9000;
background-color: #FFC000;
&:hover {
background-color: #f1b502;
}
}
@media screen and (max-width: 768px) {
thead {
display: none;
}
tbody > tr {
display: grid;
grid-gap: 0.5rem;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(3, auto);
border: 1px solid rgba(0,0,0,0.75);
border-radius: 0.25rem;
position: relative;
margin-bottom: 1rem;
padding: 1.5rem;
&::before {
content: '';
position: absolute;
width: 100%;
height: 4px;
background-color: #5B9BD5;
}
}
td {
border-bottom: none;
padding: 0;
}
.index {
display: none;
}
.product {
justify-self: start;
}
.ingredient {
grid-column: 1;
grid-row: 2;
justify-self: start;
font-size: 0.875rem;
margin-bottom: 0.75rem;
}
.price {
grid-column: 1;
grid-row: 3;
justify-self: start;
align-self: center;
}
.add-btn {
grid-column: 2;
grid-row: 3;
justify-self: end;
align-self: center;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.