1

For instance :

<div>
<span style="font-size: 20pt" id="BBB">Hello</span> 
<span style="font-size: 5pt; vertical-align: middle;" id="AAA">World</span> 
</div>

From the element BBB it's easy to get the line boundaries as BBB is the taller element of the line. Its offsetTop and offsetHeight properties are the line boundaries.

But how to get the line boundaries from the element AAA ?

Can I get that info directly, or do I have to loop through the elements of the line ?

Simon
  • 2,067
  • 2
  • 17
  • 30

2 Answers2

0

use getComputedStyle to get all the computed css properties for the rendered element and pick what you want.

The Window.getComputedStyle() method returns an object that reports the values of all CSS properties of an element after applying active stylesheets and resolving any basic computation those values may contain. Individual CSS property values are accessed through APIs provided by the object or by simply indexing with CSS property names.

i noticed that in the snippet there are not all the properties so check this Fiddle

const element = document.querySelector('#AAA');
const computed = window.getComputedStyle(element);

[...computed].forEach((e) => {
  console.log(e, ' : ', computed.getPropertyValue(e));
});
<div>
  <span style="font-size: 20pt">Hello </span>
  <span style="font-size: 5pt; display: middle;" id="AAA">World </span>
  <span style="font-size: 10pt">etc </span>
  <span style="font-size: 10pt">etc</span>
</div>
Taki
  • 17,320
  • 4
  • 26
  • 47
0

There is no API to handle line boxes.

There was that question related : How can I count text lines inside an DOM element? Can I?

And no miracle there.

Simon
  • 2,067
  • 2
  • 17
  • 30