skip to Main Content

I am finally learning CSS, but I am stuck on adding a fading, centered shadow behind text.
I’ve tried using text-shadow and box-shadow, but I have been unsuccessful. What I am trying to achieve:

enter image description here

I have found some potential solutions that use really complicated css, but I am hopeful a simpler solution exists that I am just missing.
Here is my markup:

#menu {
  position: absolute;
  top: 4.5em;
  right: 0;
}

#menu ul {
  display: inline-block;
}

#menu li {
  display: block;
  float: left;
  text-align: center;
}

#menu li:hover a,
#menu li.active a,
#menu li.active span {}

#menu li a,
#menu li span {
  padding: 1em 1.5em;
  letter-spacing: 1px;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.8em;
  color: black;
}

#menu .active a {
  background: #2651a8;
  border-radius: 6px;
  color: rgba(255, 255, 255, 1);
}

#menu .icon {}
<div id="menu">
  <ul>
    <li class="active"><a href="#" accesskey="1" title="">Homepage</a></li>
    <li><a href="#" accesskey="2" title="">FIRST</a></li>
    <li><a href="#" accesskey="3" title="">SECOND</a></li>
    <li><a href="#" accesskey="4" title="">THIRD</a></li>
    <li><a href="#" accesskey="5" title="">FOURTH</a></li>
  </ul>
</div>

2

Answers


  1. Use :before and blur filter:

    body {
      display: flex;
      min-height: 100dvh;
      margin: 0;
    }
    
    a {
      position: relative;
      padding: 8px 16px;
      margin: auto;
    }
    
    a:before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 100%;
      background-color: currentColor;
      filter: blur(10px);
      opacity: 0;
      transition: opacity .4s;
      z-index: -1;
    }
    
    a:hover:before {
      opacity: .2;
    }
    <a href="#">Lorem ipsum.</a>
    Login or Signup to reply.
  2. Box shadow ways.

    .cool-content {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 5rem;
    }
    
    .cool-content:before {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%);
      content: '';
      z-index: -1;
      box-shadow: 0 0 32px 15px rgba(0,0,0,.9);
    }
    
    .cool-content.full:before {
      width: 100%;
    }
    <div class="cool-content">COOL CONTENT</div>
    
    <div class="cool-content full">COOL CONTENT</div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search