IkNothing IkNothing - 3 months ago 26
HTML Question

Smart background div with circle but what if is background-image

I have a div and a span. Span is a circle with a border added on it. The div also has a simple background and move it - to the top. But what if the background isn't color and its background-image how to we do it so.

Sorry for my bad English

HTML

<div id="main">
<span class="circle"></span>
<div class="div">

</div>
</div>


CSS

#main {
text-align: center;
}

.circle {
background: #298EEA;
display: inline-block;
width: 80px;
height: 80px;
margin-top: 30px auto;
border-radius: 50%;
border: 15px solid #f3f5f6
}

.div {
padding: 80px 80px 60px 80px;
background: #282C39;
border-radius: 3px;
margin-top: -45px;
}


Checkout the jsfiddle

Answer

You may use a pseudo element and use a shadow to draw the background-color.

#main {
  text-align: center;
}
html {
  background: linear-gradient(45deg, white, gray, gold, purple, gray, white, gray, gold, purple, gray, white, gray, gold, purple, gray, white, gray, gold, purple, gray, white, gray, gold, purple, gray)
}
.circle {
  background: #298EEA;
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
  margin: 15px auto 0;
  border-radius: 50%;
}
.div {
  padding: 80px 80px 60px 80px;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  margin-top: -45px;
  z-index: 1;
  color:white;
}
.div:before {
  content: '';
  height: 100px;
  width: 100px;
  position: absolute;
  z-index: -1;
  top: -50px;
  left: 0;
  right: 0;
  margin: auto;
  box-shadow: 0 0 0 1000px #282C39;
  border-radius: 50%;
}
<div id="main">
  <span class="circle"></span>
  <div class="div">
    test me
  </div>
</div>