-5
I have a <div>
which will be used to store information. I want to make a kind of "table", formatting the texts and values so that they are more or less like this:
Hot Dog 2,99
Pizza 7
Carro 91000
Lasanha Sd. 13
It is a very crude example but it is in this format that I want my text. To accomplish this task, I tried to use the code below:
const info = document.getElementById("info");
info.innerHTML = "";
const totalEpisodes = `<span>${getTotalEpisodesWatched(list).padStart(10)}</span><br/>`;
const meanScore = `<span>${getMeanScore(list).padStart(10)}</span><br/>`;
info.innerHTML += "Total Episodes:".padEnd(15) + totalEpisodes;
info.innerHTML += "Mean Score:".padEnd(15) + meanScore;
The problem is that when I created this code, I completely forgot that the spaces would not appear in the final result. I know I can use the
to generate a TAB but what I really need is blank spacing to perform the formatting properly.
So my question is: how can I make the browser render the spaces in the element?
Wouldn’t it be better to use a
table
orgrid
for that? Lines may break and lose formatting, and if your site is rendered with a non-standard font it will get weird.– Andre
Just for the record
is not a tab. Also, because you do not add a code snippet?– Luiz Felipe
@user140828 yes I thought of using a
<table>
, but I don’t want those rows in the table and I don’t want that default formatting of it. If it’s to use a<table>
I want the table to have the face of a<div>
(no line, edge, or any other detail) and with the formatting I showed in the question.– JeanExtreme002
@Luizfelipe if I were to wear one code snippet to represent what I try to do in the code, it would be too big a question as I would need to put HTML, etc, etc. So I put only the part of JS code that is most important.
– JeanExtreme002
And as I mentioned in the comment above, I don’t mind using
<table>
as long as I get the formatting I want. But still as the question is about rendering blank spaces in the browser, it would be good an answer on this to help other people and not just me.– JeanExtreme002
Blank space is
. Two white spaces 
. Four white spaces 
– Augusto Vasques
He came to see this: https://answall.com/q/421374/112052?
– hkotsubo
You saw this (2): https://answall.com/questions/454404/element-alignments-no-html-e-css/454432#454432
– hugocsl
@hkotsubo was exactly what I was looking for. I did not find on the site before this question because the title of the question did not make it clear that it was about white spaces in HTML.
– JeanExtreme002