¿Hay alguna manera de saber la longitud real de div a continuación después de llenar con texto? con css (preferido) o 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>En JS, puede usar offsetWidth . También tiene offsetHeight para la altura.
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>