Menu: table layout alternate colours
Designing a menu to match designers UI/UX series.
by Stephane de Luca
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- (1) menu c2a -->
<div><a onclick="$('#myMenu').toggleClass('zid-open')">Réassort</a></div>
<!-- (2) the menu itself -->
<table id="myMenu" class="zid-open-close menu">
<tbody>
<tr onclick="issuePickedUp(event, $(this))"><td><div></div></td><td>Les soldats du feu<br>n°220</td><td><a href=""></a></td></tr>
<tr onclick="issuePickedUp(event, $(this))"><td><div></div></td><td>Les soldats du feu<br>n°221</td><td><a href=""></a></td></tr>
<tr onclick="issuePickedUp(event, $(this))"><td><div></div></td><td>Les soldats du feu<br>n°222</td><td><a href=""></a></td></tr>
<tr onclick="issuePickedUp(event, $(this))"><td><div></div></td><td>Les soldats du feu<br>n°223</td><td><a href=""></a></td></tr>
</tbody>
</table>
CSS
html {
font-family: --apple-system, sans-serif;
}
.zid-open-close {
display: none;
}
.zid-open {
display: block!important;
}
.menu {
width: 450px;
table-layout: fixed;
border-collapse: collapse;
background-color: white;
border: solid 1px lightgray;
box-shadow: rgba(0,0,0, 0.3) 0 10px 10px;
}
.menu>tbody>tr:nth-child(odd) {
background-color: hsl(0,0%,96%);
}
.menu>tbody>tr {
height: 120px; /* hauteur de la ligne 80 + 20 + 20 = 120 px*/
}
.menu>tbody>tr>td {
padding: 20px; /* padding de 20 px tout autour des cellules du tableau */
}
.menu>tbody>tr>td:first-child>div {
margin-left: 4px; /* marge à gauche un peu plus forte, qui s'additionne au
padding du td général */
width: 70px;
height: 80px;
background-color: red;
background-repeat: no-repeat;
background-position: center top;
background-size: cover;
background-image: url(https://dataimportercdn.azureedge.net/importeddata/207203/2017/05/03/images/[email protected]);
}
.menu>tbody>tr>td>a:after {
content: "Nouvelle commande";
}
JavaScript
function issuePickedUp(event, tag) {
event.stopPropagation();
alert("Vous avez sélectionné la publication ("+tag.find('td:nth-child(2)').html()+")");
}