<div class="PageHeading">
<div class="PageHeading-title">SVG vs CSS Notification Badge</div>
<div class="PageHeading-description">
Compare the alignment of text in CSS styled SVG element vs CSS styled DOM element.
</div>
</div>
<div class="PageContainer">
<div class="App">
<div class="App-label">SVG</div>
<div class="SVGBadge">
<svg class="SVGBadge-svg" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle class="SVGBadge-svgBackground" cx="10" cy="10" r="10"/>
<text class="SVGBadge-number" x="10" y="14.5" text-anchor="middle">99</text>
</svg>
</div>
</div>
<div class="App">
<div class="App-label">CSS</div>
<div class="CSSBadge">
<div class="CSSBadge-number">99</div>
</div>
</div>
</div>
html, body { padding: 50px; }
html {background-color: #efefef;}
.PageHeading {
margin-bottom: 20px;
&-title {
font-size: 22px;
font-weight: bold;
}
}
.PageContainer {
background-color: #fff;
letter-spacing: 30px; // Icon Spacing
padding: 50px;
}
.App {
display: inline-block;
font-size: 80px; // Icon Size
width: 1em;
height: 1em;
letter-spacing: 0;
position: relative;
border-radius: 20%;
background: linear-gradient(45deg, #fabbfd, #00b7b5);
box-shadow: 0 0 40px rgba(#000, 0.15);
&-label {
font-size: 14px;
position: absolute;
top: 100%;
left: 0;
right: 0;
margin-top: 10px;
text-align: center;
}
}
.SVGBadge {
&-svg {
font-size: 30px;
position: absolute;
bottom: 100%;
left: 100%;
width: 1em;
height: 1em;
margin-left: -0.6em;
margin-bottom: -0.6em;
}
&-svgBackground {
fill: red;
}
&-number {
fill: white;
font-family: sans-serif;
font-size: 12px;
letter-spacing: -1px;
}
}
.CSSBadge {
box-sizing: border-box;
color: white;
font-family: sans-serif;
font-size: 30px;
letter-spacing: -1px;
position: absolute;
bottom: 100%;
right: 0;
min-width: 1em;
padding-left: 0.2em;
padding-right: 0.2em;
height: 1em;
margin-bottom: -0.6em;
margin-right: -0.6em;
background-color: #f00;
border-radius: 1em;
text-align: center;
line-height: 1em;
&-number {
font-size: 0.6em;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.