Skip to content

Fix extra height under inline-block .text-truncate - #43414

Open
ngocanhnckh wants to merge 1 commit into
twbs:mainfrom
ngocanhnckh:fix/text-truncate-extra-height
Open

ngocanhnckh wants to merge 1 commit into
twbs:mainfrom
ngocanhnckh:fix/text-truncate-extra-height

Conversation

@ngocanhnckh

Copy link
Copy Markdown
  • .text-truncate on an inline-block element adds about 6px of space below it. The line box keeps room for descenders. This happens at all widths.
  • Cause: overflow: hidden moves the baseline of an inline-block to its bottom edge. The element sits on the parent baseline, and the space for descenders stays below it.
  • Fix: add vertical-align: top to the text-truncate mixin. This is the fix that the issue suggests.
  • Block and flex items do not change. The property has no effect on them. Plain <div class="text-truncate"> has no gap before or after.
  • Test: the box around <span class="d-inline-block text-truncate"> is 32px high before and 26px after. This is the 2px border plus a 24px line. I checked 320, 375, 414, 768, 820, 1024 and 1440px, light and dark.
  • A d-block text-truncate child inside a plain inline-block wrapper still has the gap. The wrapper causes that gap, not the helper.
  • npm run css-lint, npm run css, npm run css-test and npm run docs-build pass.
  • Issue 36943 says "display block". Only inline-block shows the gap on current main.

The red boxes in the before shots mark the broken part.

Width Before After
375px, light Before, 375px light After, 375px light
768px, dark Before, 768px dark After, 768px dark

I maintain renderlint, an open-source CLI that renders pages in a headless browser and reports layout defects. I ran it on the text truncation and typography docs pages before and after this change. It reports no new problems. If it is useful, I can open a follow-up PR that runs it on the docs in CI.

Fixes #36943

An element with `overflow: hidden` has its baseline at its bottom edge.
An inline-block `.text-truncate` therefore sits on the baseline of the
parent line. The line box adds space for the descenders below it.

Set `vertical-align: top` in the `text-truncate` mixin. The extra space
goes away. The property has no effect on block and flex items.

Fixes twbs#36943
@ngocanhnckh
ngocanhnckh requested a review from a team as a code owner November 20, 2026 04:38
@julien-deramond julien-deramond added v6 v6, the main branch bug Something does not work as documented css Sass sources or compiled CSS labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something does not work as documented css Sass sources or compiled CSS v6 v6, the main branch

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

text-truncate adding extra height to display block elements

2 participants