wpt / css / css-inline / text-box-trim / text-box-trim-initial-letter-start-001.html

Status: PASS | Duration: 7ms | Subtests: 1/1 | Open test on wpt.live | Open ref on wpt.live | wpt.fyi

/css/css-inline/text-box-trim/text-box-trim-initial-letter-start-001.html

<!DOCTYPE html>
<title>text-box-trim: trim-start works even in the presence of initial-letter</title>
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-trim">
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#text-box-edge">
<link rel="match" href="text-box-trim-initial-letter-start-001-ref.html">
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<style>
.spacer {
  height: 50px;
  background: lightgray;
}
.target {
  font: 40px/1 Ahem;
  text-box-trim: trim-start;
  text-box-edge: text;
}
.target::first-letter {
  initial-letter: 2 1;
}
</style>
<div class="spacer"></div>
<div class="target">ApÉx</div>

/css/css-inline/text-box-trim/text-box-trim-initial-letter-start-001-ref.html

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<style>
.spacer {
  height: 50px;
  background: lightgray;
}
.target {
  font: 40px/1 Ahem;
  position: relative;
}
.target::first-letter {
  initial-letter: 2 1;
}
</style>
<div class="spacer"></div>
<div class="target">ApÉx</div>
<script>
// The font size of raised initial letters is undefined[1].
// Implementations, especially when using Ahem as a web font, don't match.
// To test the `text-box-trim` behavior by ignoring such differences, compute
// the expected position of the `target` dynamically.
// [1] https://drafts.csswg.org/css-inline-3/#sizing-initial-letter
const spacer = document.getElementsByClassName('spacer')[0];
const target = document.getElementsByClassName('target')[0];
const spacer_bottom = spacer.getBoundingClientRect().bottom;
const target_bottom = target.getBoundingClientRect().bottom;
target.style.top = `${spacer_bottom - target_bottom + 40}px`;
</script>