Categories
CSS Snippets

CSS-only Responsive Navigation Menu

In one of the many unsuccessful job applications I have completed this one required me to build a navigation menu as a technical test.

I decided to build one entirely in CSS rather than using a JavaScript library like jQuery which was “allowed”.

I didn’t get the job but I can always display what I completed here.

@import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");
* {
  margin: 0;
  padding: 0; }

body, button, input, select, textarea {
  font-family: 'Open Sans', sans-serif;
  color: #222; }

a {
  color: #282b34; }

a:visited {
  color: #48516b; }

a:focus {
  outline: thin dotted; }

a:hover, a:active {
  outline: 0; }

nav {
  text-align: center;
  padding: 10px;
  background-color: #e2e2e2; }

nav .menu-item {
  display: inline-block;
  width: 150px;
  border-bottom: solid 2px #ea5a0b;
  border-right: 2px solid transparent;
  border-left: 2px solid transparent;
  border-top: 2px solid transparent;
  transition: all .75s;
  margin: 3px; }

.has-child ul {
  display: none;
  background-color: #e2e2e2;
  border: solid 2px #ea5a0b; }

.has-child:hover > ul {
  display: block;
  float: left;
  list-style: none;
  width: 150px;
  text-align: left;
  position: absolute;
  margin-top: 10px;
  margin-left: -1.5px; }

nav .menu-item a {
  text-decoration: none;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 15px;
  padding-right: 15px; }

.has-child ul li {
  border: none; }

.has-child ul li:hover {
  border: none; }

nav .menu-item:hover {
  border-right: solid 2px #ea5a0b;
  border-left: solid 2px #ea5a0b;
  border-top: solid 2px #ea5a0b; }

.burger {
  display: none;
  cursor: pointer;
  width: 35px;
  margin: auto; }

.bar1, .bar2, .bar3 {
  width: 35px;
  height: 5px;
  background-color: #333;
  margin: 6px 0;
  transition: 0.4s; }

#burger:checked ~ .burger > .bar1 {
  -webkit-transform: rotate(-45deg) translate(-9px, 6px);
  transform: rotate(-45deg) translate(-9px, 6px); }

#burger:checked ~ .burger > .bar2 {
  opacity: 0; }

#burger:checked ~ .burger > .bar3 {
  -webkit-transform: rotate(45deg) translate(-8px, -8px);
  transform: rotate(45deg) translate(-8px, -8px); }

#burger:checked ~ .nav {
  display: block !important; }

#burger {
  display: none; }

.container {
  margin: auto;
  width: 90%;
  max-width: 1600px; }

@media only screen and (max-width: 320px) {
  /* BASE
	=================== */
  /* LAYOUT
	=================== */
  /* MODULE
	=================== */ }

@media only screen and (max-width: 480px) {
  .nav {
    display: none; }
  .burger {
    display: block; } }