Is there a method to conceal text and create an underline of identical length in an HTML document? In this technique, certain highlighted words remain hidden, substituted with underlines that match the original text's length precisely. Additionally, all sentence words should maintain their original locations even after clozing. For instance:
Once upon a time there ______ a cat.
The word intended for clozing may be indicated as follows:
Once upon a time there <div class="cloze">lived</div> a cat.
How can I implement text hiding and underline creation with matching lengths?