<body>
<small>This text is kinda small.</small>
<h3>How about this?</h3>
<h2>Better. But I know we can do more.</h2>
<h1>Now that's what I'm talking about.</h1>
<div id="fontSizeIndicator"></div>
</body>
body {
text-align: center;
margin-top: 2em;
font-family: apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans,
Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
#fontSizeIndicator {
position: fixed;
font-size: 1.2rem;
background: green;
color: white;
box-shadow: 0 0 12px rgba(0, 0, 0, 0.5);
top: .5em;
left: .5em;
display: inline-block;
padding: .5em;
border: 2px solid white;
border-radius: 0.5em;
&::before {
content: "Font size: ";
}
}
h1 {
font-size: 4rem;
}
h3 {
font-size: 1.5rem;
}
h2 {
font-size: 2rem;
}
View Compiled
document.addEventListener("selectionchange", (e) => {
const sel = window.getSelection();
if (sel.rangeCount) {
const indicator = document.getElementById("fontSizeIndicator");
indicator.innerText = window.getComputedStyle(
sel.getRangeAt(0).startContainer.parentNode
).fontSize;
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.