1

Is it possible to achieve this in pure css, without requiring to use an embedded SVG in your page.

Obvs border-radius: 10px doesn't quite cut it.

enter image description here

digout
  • 4,041
  • 1
  • 31
  • 38

2 Answers2

2

Here is a quick example where we change the top and bottom border-radiuses. We can use the other value as a weird kind of height thing which will control the height of our radius.

.box {
    background: #62f;
    color: white;
    border-radius: 50% / 10px;
    padding: 30px;
    width: 1em;
    height: 1em;
}
<div class="box">8</div>

Now then, we can use the ::before and ::after selector to make two of these:

.box::after {
    background: #62f;
    color: white;
    border-radius: 50% / 10px;
    padding: 30px;
    width: 1em;
    height: 1.75em;
    content: "";
    display: block;
    position: absolute;
    top: 2px;
    left: 8px;
}

.box::before {
    background: #62f;
    color: white;
    border-radius: 10px / 50%;
    padding: 30px;
    width: 1.75em;
    height: 1em;
    content: "";
    display: block;
    position: absolute;
    top: 8px;
    left: 2px;
}
<div class="box">8</div>

Now then, I hear you ask, what about our 8? Where has it gone? Well, my friends, it has actually gone behind our weird square. We can wrap it in a span and style this to fix this.

.box::after {
    background: #62f;
    color: white;
    border-radius: 50% / 10px;
    padding: 30px;
    width: 1em;
    height: 1.75em;
    content: "";
    display: block;
    position: absolute;
    top: 2px;
    left: 8px;
}

.box::before {
    background: #62f;
    color: white;
    border-radius: 10px / 50%;
    padding: 30px;
    width: 1.75em;
    height: 1em;
    content: "";
    display: block;
    position: absolute;
    top: 8px;
    left: 2px;
}

.box > span {
    position: absolute;
    top: 32px;
    left: 36px;
    z-index: 5;
    color: white;
    font-size: 1.5em;
    font-family: sans-serif;
}
<div class="box"><span>8</span></div>

We can also swap a few numbers around to make it even more perfect as well:

.box::after {
    background: #62f;
    color: white;
    border-radius: 50% / 20px;
    padding: 30px;
    width: 1em;
    height: 1.75em;
    content: "";
    display: block;
    position: absolute;
    top: 2px;
    left: 8px;
}

.box::before {
    background: #62f;
    color: white;
    border-radius: 20px / 50%;
    padding: 30px;
    width: 1.7em;
    height: 1em;
    content: "";
    display: block;
    position: absolute;
    top: 8px;
    left: 2px;
}

.box > span {
    position: absolute;
    top: 32px;
    left: 36px;
    z-index: 5;
    color: white;
    font-size: 1.5em;
    font-family: sans-serif;
}
<div class="box"><span>8</span></div>
corn on the cob
  • 2,093
  • 3
  • 18
  • 29
0

Hope this helps:

.square{
  height:80px;
  width:80px;
  background:blue;
  display:flex;
  justify-content:center;
  align-items:center;
  color:#fff;
  border-radius:2rem;
  font-size: 2rem;
  opacity: 0.5;
  box-shadow:-1px 1px 1px 1px #fff;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div class="square">8</div>
</body>
</html>
Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35