JSFiddle - React, Tailwind, and code Playground

HTML

<div id="main"> 
     <div id="sidebar"></div>
     <div id="body">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</div>
 </div>

CSS

body {
     background: black;  
}

#main {
     background: white;
}

JavaScript

$(function() {
    $.fn.textWidth = function(){
      var html_org = $(this).html();
      var html_calc = '<span>' + html_org + '</span>'
      $(this).html(html_calc);
      var width = $(this).find('span:first').width();
      $(this).html(html_org);
      return width;
    };
    
     $("#main").css("width", $("#body").textWidth());
});