Search code examples
htmlcssbox-shadow

How to add a blur behind a <div>?


I have this: Box with rounded corners has a white body, a dark blue header, and a grey footer.

I want to add box shadow border like this so that we can see the white part: Box with a light grey shadow extending from all four sides.

For the moment my HTML structure looks like this:

<div class="card-post">

  <div class="top">
    <div class="my-container">

      <div class="left">
        <img src="profile-picture.svg" alt="">
      </div>

      <div class="middle">
        <p>Username</p>
      </div>

      <div class="right">
        <img src="more-btn.svg" alt="">
      </div>

    </div>


  </div>

  <div class="content">

  </div>

  <div class="bottom">
  </div>
</div>

Solution

  • Just use

    .content {
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }
    

    .top-section {
      background: #293c7c;
      border-top-left-radius: 50px;
      border-top-right-radius: 50px;
      padding: 10px 20px;
      display: flex;
      align-items: center;
      
    }
    img.user-img {
        max-width: 100%;
    }
    .uname {
      font-size: 35px;
      color: #fff;
      text-align: left;
    }
    .dot-btn {
      max-width: 30%;
      float: right;
    }
    .content {
        height: 300px;
        margin: 0;
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }
    .bottom {
        background: #8b8b8b;
        height: 100px;
        border-bottom-right-radius: 50px;
        border-bottom-left-radius: 50px;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <div class="container">
      <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
          <div class="top-section">
            <div class="col-md-2 col-sm-2 col-xs-2">
              <div class="left">
                <img class="user-img" src="https://upload.wikimedia.org/wikipedia/commons/d/d3/User_Circle.png" alt="">
              </div>
            </div>
            <div class="col-md-5 col-sm-5 col-xs-4">
              <div class="middle">
                <p class="uname">Username</p>
              </div>
            </div>
            <div class="col-md-5 col-sm-5 col-xs-8">
              <div class="right">
                <img class="dot-btn" src="https://d30y9cdsu7xlg0.cloudfront.net/png/334917-200.png" alt="">
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-12 col-sm-12 col-xs-12">
          <div class="content">
          </div>  
        </div>  
        <div class="col-md-12 col-sm-12 col-xs-12">
          <div class="bottom">
          </div>
        </div>
      </div>
    </div>