htmlcssshadow

css div gradient shadow/border


I am trying to achieve this:

I couldn't find anything like it, but here is my failed attempt:

#one {
  width: 200px;
  height: 100px;
  background-color: white;
  box-shadow: 0px 0px 20px #2D8DBD;
  left: 50px;
  display: inline-block;
  margin-right: -100px;
}
#two {
  width: 200px;
  height: 100px;
  background-color: white;
  box-shadow: 0px 0px 20px #B22D2D;
  left: -50px;
  display: inline-block;
  margin-left: -50px;
  z-index: -1;
}
<center>
  </br>
  </br>
  <div id="one"></div>
  <div id="two"></div>
</center>

jsFiddle demo.

I am using bootstrap, so I don't think just making another "gradient" image would be simpler.

Also, I have tried compromising for this: http://designposts.net/fresh-free-css3-and-html5-tutorials/ but my image is circled, and so it turns out as a cut square.


Solution

  • You can fake one, using background gradient and a box-shadow, as well as a css pseudo element to mask the border. Note that if you change the background color of the surrounding content you have to change every instance of #444

    .outer {
        box-sizing: border-box;
        padding: 25px;
        height: 200px;
        width: 200px;
        box-shadow: 0px 0px 10px 10px #444 inset;
        border-radius: 50%;
        background: linear-gradient(to bottom right, rgb(250,50,50), rgb(50,150,250));
    }
    .outer::before {
        content: "";
        display: block;
        position: relative;
        left: -26px;
        top: -26px;
        height: 202px;
        width: 202px;
        border-radius: 50%;
        border: 3px solid #444;
        box-sizing: border-box;
    }
    .inner {
        position:relative;
        top: -204px;
        left: -3px;
        border-radius: 50%;
        background: linear-gradient(to bottom right, #ee2135, #6279ff);
        padding: 2px;
        height: 150px;
        width: 150px;
        box-shadow: 0px 0px 30px -5px black;
    }
    .content {
        height: 100%;
        width: 100%;
        background: #444;
        border-radius: 50%;
    }
    
    /* Styling only past here */
    html, body {
        text-align: center;
        padding: 0px;
        margin: 0px;
        height: 100%;
        background: #444;
    }
    body::before {
        content: "";
        display: inline-block;
        vertical-align: middle;
        height: 100%;
    }
    .outer {
        display: inline-block;
        vertical-align: middle;
    }
    <div class="outer">
        <div class="inner">
            <div class="content">
            </div>
        </div>
    </div>