Gabriel Bontorin
Gabriel Bontorin

Reputation: 13

Make menu in CSS like in the picture

I have questions about how to reproduce the following: enter image description here

I would like to know how I should proceed to make this menu conform to the picture above. I do not want anything ready, but a way to get the expected result.

So far, I have the following code:

body{
  background: white;
  margin: 0;
  padding: 0;
}
nav {
  width: 100%;
  background: #000;
  border-bottom: 5px solid white;
}
nav:after{
  content: '';
  border-bottom: 10px solid black;
  width: 100%;
  position: fixed;
  margin-top: 5px;
}
nav li {
  display: inline-block; 
  list-style: none;
}
nav li a {
  color: #fff;
  display: inline-block; 
  font-weight: bold; 
  padding: 20px 15px 15px 15px; 
  text-decoration: none;
}
nav li a:hover {
  background: red;
  color: #fff;
}
nav li a:hover:after {
  content: '';
  border-bottom: 10px solid yellow;
  position: fixed;
  width: auto;
  margin-top: 54px;
  left: 0;
  right: 0;
  z-index: 1;
}
<nav>
 <ul>
  <li><a href="">Menu 1</a></li>
  <li><a href="">Menu 2</a></li>
  <li><a href="">Menu 3</a></li>
 </ul>
</nav>

I hope someone can help me. Thank you in advance!

Upvotes: 0

Views: 99

Answers (3)

jseezo
jseezo

Reputation: 472

You can try this solution should be helpful

body {
  background: white;
  margin: 0;
  padding: 0;
}

nav {
  width: 100%;
  background: #000;
  border-bottom: 5px solid white;
  position: relative;
}

nav:after {
  content: '';
  height: 8px;
  width: 100%;
  background: inherit;
  position: absolute;
  bottom: -15px;
  left: 0px;
  z-index: 1;
}

nav ul {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  max-width: 100%;
  margin: auto;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  padding-bottom: .6em;
}

nav li {
  display: inline-block;
  list-style: none;
  position: relative;
  padding: 0 .5em;
}
nav li:last-child a:before {
  display: none;
}

nav li a {
  color: #fff;
  display: inline-block;
  padding: 1.6em 0.6em 0.7em 0.6em;
  text-decoration: none;
  position: relative;
  font-size: 18px;
  line-height: 1;
}
nav li a:before {
  content: "|";
  display: block;
  position: absolute;
  right: -10px;
  top: 1.6em;
  -webkit-transform: translateY(-4%);
          transform: translateY(-4%);
  line-height: inherit;
  font-size: inherit;
  color: #fff;
}
nav li a:after {
  display: none;
  content: "";
  position: absolute;
  bottom: -25px;
  left: 0px;
  width: 100%;
  height: 8px;
  background: #ffaf1a;
  z-index: 2;
}

nav li a:hover {
  background: red;
  color: #fff;
}
nav li a:hover:after {
  display: block;
}
<nav>
 <ul>
  <li><a href="">Menu 1</a></li>
  <li><a href="">Menu 23</a></li>
  <li><a href="">Menu 345</a></li>
  <li><a href="">Menu 44567</a></li>
  <li><a href="">Menu 567889</a></li>
 </ul>
</nav>

Upvotes: 2

yaakov
yaakov

Reputation: 4675

Stick the elements out of the bottom of the nav with this code: https://jsfiddle.net/d379Lagm/

body{
  background: white;
  margin: 0;
  padding: 0;
}
nav {
  width: 100%;
  background: #000;
  border-bottom: 5px solid white;
  outline: 5px solid #000;

}


nav ul {
  list-style: none;
  padding: 0;
  margin: 0;

}

nav li {
  display: inline-block; 
  list-style: none;
}
nav li a {
  color: #fff;
  display: inline-block; 
  font-weight: bold; 
  padding: 20px 15px 15px 15px; 
  text-decoration: none;
  position: relative;
  border-bottom: 5px solid transparent;
}
nav li a:hover {
  background: red;
  color: #fff;

}
nav li a:after {
  position: absolute;
  left: 0;
  right: 0;
  background: transparent;
  height: 5px;
  content: "";
  transform: translateY(950%);
}
nav li a:hover:after {
  background: yellow;

}

Upvotes: 0

Federico
Federico

Reputation: 3930

Here it is: https://jsfiddle.net/97cyvmcy/

Simply, just use two linear gradients to achieve the desired effect:

One with red and yellow stripes:

li a:hover {
  background: linear-gradient(to bottom, red 0%, red 90%, yellow 90%, yellow 100%);
}

And the other with black and white stripes at the bottom:

nav:after {
  content:' ';
  width: 100%;
  height: 15px;
  position: absolute;
  bottom: 10px;
  background:linear-gradient(to bottom, black 0%, black 50%, white 50%, white 100%);
}

Upvotes: 0

Related Questions