Skip to content

Instantly share code, notes, and snippets.

@chirag-chhajed
Created July 21, 2026 14:57
Show Gist options
  • Select an option

  • Save chirag-chhajed/085405d8d5c1a82f10a8b372c186995c to your computer and use it in GitHub Desktop.

Select an option

Save chirag-chhajed/085405d8d5c1a82f10a8b372c186995c to your computer and use it in GitHub Desktop.
* ── Resize handle ──────────────────────────────── */
.resize-box {
resize: horizontal;
overflow: hidden;
width: 100%;
max-width: 100%;
min-width: 4ch;
border: 1px solid hsl(0 0% 20%);
border-radius: 6px;
padding: 12px 16px;
background: hsl(0 0% 6%);
cursor: col-resize;
}
/* ── 01 Standard truncation ────────────────────── */
.standard-truncate {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
/* ── 02 RTL truncation ─────────────────────────── */
.rtl-truncate {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
direction: rtl;
text-align: left; /* keep visual alignment LTR */
}
/* ── 03 Center truncation ──────────────────────── */
/*
* The UUID is 36 chars. In monospace 1ch = 1 character, so
* 36ch is the exact width of the full string.
*
* >= 36ch → full string, no truncation, ::after + ::before hidden
* < 36ch → two halves (each max 50%), LTR left + RTL right,
* both use text-overflow: clip.
* ::before sits in the center with "..." content and
* a gradient bg that fades from transparent → bg → transparent,
* smoothly masking the junction.
*/
.center-truncate {
--_bg: hsl(0 0% 6%);
container-type: inline-size;
display: flex;
overflow: hidden;
position: relative;
}
/* ── shared base for both text layers ── */
.center-truncate > span {
flex: 0 1 auto;
overflow: hidden;
white-space: nowrap;
}
.center-truncate::after {
content: attr(data-string);
flex: 0 1 auto;
overflow: hidden;
white-space: nowrap;
}
/* ── the "..." overlay ── */
.center-truncate::before {
content: "\2026"; /* … unicode ellipsis */
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
z-index: 1;
white-space: nowrap;
/* gradient: transparent → bg → bg → transparent */
background: linear-gradient(
to right,
transparent,
var(--_bg) 2ch,
var(--_bg) calc(100% - 2ch),
transparent
);
/* 3ch for "..." + 2ch fade each side = ~7ch total */
padding: 0 2ch;
pointer-events: none;
display: none;
}
/* ── wide: full string fits ── */
@container (min-width: 36ch) {
.center-truncate > span {
max-width: 100%;
text-overflow: clip;
}
.center-truncate::after {
display: none;
}
.center-truncate::before {
display: none;
}
}
/* ── narrow: center-truncate ── */
@container (max-width: calc(36ch - 1px)) {
.center-truncate > span {
min-width: 3ch;
max-width: 50%;
text-overflow: clip;
}
.center-truncate::after {
min-width: 3ch;
max-width: 50%;
text-overflow: clip;
direction: rtl;
text-align: right;
}
.center-truncate::before {
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment