Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
getting text block length with css (preferred) or javascript

Is there a way to know the actual length of div below after filling with text? with css (preferred) or javascript.

*{
  margin:0;
  padding:0;
}

div{
  display:inline-block;
  background-color:steelblue;
  font-family: roboto;
}
<div>what is my length?</div><br/>
<div>what is my length then????</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In JS, you can use offsetWidth. You also have offsetHeight for the height.

console.log(document.getElementById("a").offsetWidth);
console.log(document.getElementById("b").offsetWidth);
*{
  margin:0;
  padding:0;
}

div{
  display:inline-block;
  background-color:steelblue;
}
<div id="a">what is my length?</div><br/>
<div id="b">what is my length then????</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!