Sheju Sathyanesan
Sheju Sathyanesan

Reputation: 7

Double border CSS

I have been working on a project and I was able to create a double border css with box shadow... but the problem is I need a transparency on the first box..

I tried something:

* {
  box-sizing: border-box;
}

body {
  display: flex;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
}

.box {
  width: 5rem;
  height: 3rem;
  background-color: #789;
  border: 3px solid black;
  box-shadow: 8px -8px 0 -3px #ccc, 8px -8px 0 0 #000;
}
<div class="box"></div>

I need http://prntscr.com/nw6fed - the background of the first box should be transparent...Any help

Upvotes: 0

Views: 188

Answers (1)

JasonB
JasonB

Reputation: 6378

You can get your second border with a pseudo element. I used :after in this example.

.box {
  width: 200px;
  height: 200px;
  border: 3px solid cyan;
  position: relative;
  padding: 40px;
  box-sizing: border-box;
}

.box::after {
  content: '';
  height: 100%;
  width: 100%;
  position: absolute;
  display: block;
  top: 20px;
  left: 20px;
  border: 3px solid magenta;
}
<div class="box">
  <h1>Text</h1>
</div>

Upvotes: 4

Related Questions