Back

CSS-only Responsive Navigation Menu

Posted by

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.

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; } }
<nav>
          <div class="container">
            <img class="logo" src="./img/mso-web-agency-logo.png">
            <input type="checkbox" id="burger" class="burger">
              <label for="burger" class="burger">
                <div class="bar1"></div>
                <div class="bar2"></div>
                <div class="bar3"></div>
            </label>
              <ul class="nav">
                <li class="menu-item"><a href="#">Home</a></li>
                <li class="menu-item"><a href="#">About Us</a></li>
                <li class="menu-item has-child"><a href="#">Services</a>
                    <ul>
                        <li class="menu-item"><a href="#">Web Design</a></li>
                        <li class="menu-item"><a href="#">Branding</a></li>
                        <li class="menu-item"><a href="#">Consultancy</a></li>
                        <li class="menu-item"><a href="#">SEO</a></li>
                    </ul>
                </li>
                <li class="menu-item"><a href="#">Our Work</a></li>
                <li class="menu-item"><a href="#">Contact Us</a></li>
              </ul>
            </div>
        </nav>

Comments:

Warning No comments found.

Leave a Reply