Skip to content

Instantly share code, notes, and snippets.

@natevw
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natevw/f4e090d0c6a98e5d6fd9 to your computer and use it in GitHub Desktop.
Save natevw/f4e090d0c6a98e5d6fd9 to your computer and use it in GitHub Desktop.
Overflowed element styling
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>Fade test</title>
<style>
div {
/* this is the main box we're filling */
min-height: 1em;
max-height: 3em;
width: 55px;
/* DISPLAY EXTRAS */
margin: 8px;
display: inline-block;
vertical-align: top;
line-height: 1em;
overflow: hidden;
}
span {
/* this wrapper is key — it gives us access to the total height of the text */
position: relative;
display: block;
}
span::after {
content: "";
display: block;
box-shadow: inset 0 -1em 1em -0.25em white;
position: absolute;
width: 100%;
/* here's the magic — height gets clamped between 0 and 1em… */
max-height: 1em;
height: calc(100% - 3em);
/* …and */
bottom: calc(100% - 3em);
}
#debug {
display: block;
font-family: monospace;
text-decoration: none;
}
#debug:focus {
width: 0; height: 0;
white-space: nowrap;
}
#debug::before {
content: "- ";
}
#debug:focus::before {
content: "X ";
}
#debug:focus ~ div {
overflow: visible;
box-sizing: border-box;
border: 1px solid red;
margin-top: 1.3em;
}
#debug:focus ~ div span::after {
box-sizing: border-box;
border: 1px solid rgba(0,0,255,0.1);
background: rgba(0,255,0,0.2);
}
</style>
</head><body>
<a id=debug href="#" onclick="return false;">Debug</a>
<div><span></span></div>
<div><span>Test short.</span></div>
<div><span>Test three lines.</span></div>
<div><span>Test a whole bunch of lines.</span></div>
<div><span>Test an even longer bunch of lines.</span></div>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment