Hover in navigation with html and css

2

Well folks, it's the following, I've been following this for some time. I'm trying to make a box around the links in hover , this box will have a shadow and rounded corners, can someone help me?

Thanks in advance

.main-nav {
  background-color: #2c3136;
  width: 100%;
  height: 70px;
  text-align: center;
  box-shadow: 0 0 5 0 #000;
}

.main-nav li {
  display: inline;
  list-style: none;
}

.main-nav li a {
  text-decoration: none;
  color: white;
  margin-right: 50px;
  font-size: 90%;
  font-weight: bold;
}

.main-nav li a:link .main-nav li a:visited {
  padding: 8 0;
  color: #fff;
  background: transparent;
  transition: background 0.3s ease-in-out;
}

.main-nav li a:hover,
.main-nav li a:active {
  color: #fff;
  background: #5a5a5a;
  transition: background 0.3s ease-in-out;
}
<div class="row">
  <nav class="main-nav nav-js">
    <img class="logo" src="" alt="">
    <ul>
      <li><a href="#about_us">ABOUT US</a></li>
      <li><a href="#search">SEARCH</a></li>
      <li><a href="#top_artists">TOP ARTISTS</a></li>
      <li><a href="#contacts">CONTACTS</a></li>
    </ul>
  </nav>
</div>

Example box: link

The box I want is in the li.

    
asked by anonymous 25.04.2018 / 16:07

2 answers

1

You could use the pseudo element ::before and ::after combined and apply background: radial-gradient(...) (the same has been done on the site) in these elements.

It will also be necessary to put position: relative; to align these elements above and below each menu, for example:

/*remove espaçamentos*/
.menu, .menu li {
    margin: 0;
    padding: 0;
}

.menu {
    background-color: #1d4888;
    min-width: 800px; /* pode fixar a largura com width ou colocar uma largura minima */
    white-space: nowrap; /* impede que os menus quebrem */
    text-align: center; /* impede que os menus quebrem */
}

.menu > li {
    background-color: #1d4888;
    position: relative;
    list-style-type: none;
    display: inline-block;
    width: 150px;
}

.menu > li > a {
    padding: 15px 0;
    color: #fff;
    text-decoration: none;
    display: block;
}

.menu > li > a:hover {
    background-color: #333;
}

.menu > li > a::after,
.menu > li > a::before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    content: "";
    opacity: 0;
}

.menu > li > a::after {
     top: 100%;
     background: -webkit-radial-gradient(50% -50%, ellipse, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 80%);
    background: radial-gradient(ellipse at 50% -50%, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 80%);
}

.menu > li > a::before {
     top: -5px;
     background: -webkit-radial-gradient(50% 150%, ellipse, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 80%);
     background: radial-gradient(ellipse at 50% 150%, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 80%);
}

.menu > li > a:hover::after,
.menu > li > a:hover::before {
    opacity: 1;
}
<ul class="menu">
    <li><a href="#about_us">ABOUT US</a></li>
    <li><a href="#search">SEARCH</a></li>
    <li><a href="#top_artists">TOP ARTISTS</a></li>
    <li><a href="#contacts">CONTACTS</a></li>
</ul>
    
25.04.2018 / 18:32
-1

.main-nav {
  background-color: #2c3136;
  width: 100%;
  height: 70px;
  text-align: center;
  box-shadow: 0 0 5 0 #000;
}

.main-nav li {
  display: inline;
  list-style: none;
}

.main-nav li a {
  text-decoration: none;
  color: white;
  margin-right: 50px;
  font-size: 90%;
  font-weight: bold;
}

.main-nav li a:link .main-nav li a:visited {
  padding: 8 0;
  color: #fff;
  background: transparent;
  transition: background 0.3s ease-in-out;
}

.main-nav li :hover,
.main-nav li :active {
  color: #fff;
  background: #5a5a5a;
  transition: background 0.3s ease-in-out;
  border-radius: 4px;
  box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<div class="row">
  <nav class="main-nav nav-js">
    <img class="logo" src="" alt="">
    <ul>
      <li><a href="#about_us">ABOUT US</a></li>
      <li><a href="#search">SEARCH</a></li>
      <li><a href="#top_artists">TOP ARTISTS</a></li>
      <li><a href="#contacts">CONTACTS</a></li>
    </ul>
  </nav>
</div>
    
26.04.2018 / 18:58