问题
How can I use the common \t escape character in html ? Is it possible?
I need a code that has the same function as the /t escape character
回答1:
I need a code that has the same function as the /t escape character
What function do you mean, creating a tabulator space?
No such thing in HTML, you'll have to use HTML elements for that. (A <table> may make sense for tabular data, or a description list <dl> for definitions.)
回答2:
You can enter the tab character (U+0009 CHARACTER TABULATION, commonly known as TAB or HT) using the character reference 	
. It is equivalent to the tab character as such. Thus, from the HTML viewpoint, there is no need to “escape” it using the character reference; but you may do so e.g. if your editing program does not let you enter the character conveniently.
On the other hand, the tab character is in most contexts equivalent to a normal space in HTML. It does not “tabulate”, it’s just a word space.
The tab character has, however, special handling in pre
elements and (although this not that well described in specifications) in textarea
and xmp
element (in the latter, character references cannot be used, only the tab character as such). This is described somewhat misleadingly in HTML specifications, e.g. in HTML 4.01: “[Inside the pre
element, ] the horizontal tab character (decimal 9 in [ISO10646] and [ISO88591] ) is usually interpreted by visual user agents as the smallest non-zero number of spaces necessary to line characters up along tab stops that are every 8 characters. We strongly discourage using horizontal tabs in preformatted text since it is common practice, when editing, to set the tab-spacing to other values, leading to misaligned documents.”
The warnings are unnecessary except as regards to the potential mismatch of tabbing in your authoring software and HTML rendering in browsers. The real reason for avoiding horizontal tab is that it a coarse and simplistic tool as compared with tables for presenting tabular material. And in displaying computer source programs, it is better to use just spaces inside pre
, since the default tab stops at every 8 characters are quite unsuitable for any normal code indentation style.
In addition, in CSS, you can specify white-space: pre (or, with slightly more limited browser support, white-space: pre-wrap
) to make a normal HTML element, like div
or p
, rendered like pre
, so that all whitespace is preserved and horizontal tab has the “tabbing” effect.
In CSS Text Module Level 3 (Last Call working draft, i.e. proceeding towards maturity), there is also the tab-size property, which can be used to set the distance between tab stops, e.g. tab-size: 3
. It’s supported by newest versions of most browsers, but not IE (not even IE 11).
回答3:
would be a work around if you're only after the spacing.
回答4:
HTML doesn't have escape characters (as it doesn't use escape-semantics for reserved characters, instead you use SGML entities: &
, <
, >
and "
).
SGML does not have a named-entity for the tab character as it exists in most character sets (i.e. 0x09
in ASCII and UTF-8), rendering it completely unnecessary (i.e. simply press the Tab key on your keyboard). If you're working with code that generates HTML (e.g. a server-side application, e.g. ASP.NET, PHP or Perl, then you might need to escape it then, but only because the server-side language demands it - it has nothing to do with HTML, like so:
echo "<pre>\t\tTABS!\t\t</pre>";
But, you can use SGML entities to represent any ISO-8859-1 character by hexadecimal value, e.g. 	
for a tab character.
回答5:
This simple formula should work.
Give the element whose text will contain a tab the following CSS property:
white-space:pre
.
Otherwise your html may not render tabs at all. Then, wherever you want to have a tab in your text, type 	
.
Since you didn't mention CSS, if you want to do this without a CSS file, just use
<tag-name style="white-space:pre">text in element	more text</tag-name>
in your HTML.
回答6:
I can not give a direct answer, but maybe someone still finds this useful. The same issue exists for a Mediawiki: It does not provide tabs nor are consecutive spaces allowed.
Although not really a TAB function, the workaround was to add a template named 'Tab', which replaces each call (i.e. {{tab}}) by 4 non-breaking space symbols:
Those are not collapsed and create a 4 space distance anyhwere used. Its not really a tab, because it would not align to fixed tab positions, but I still find many uses for it.
Maybe someone can come up with similar mechanism for a Wiki Template in HTML (CSS class or whatever).
回答7:
You can use this
 
or  
It works on Visual Studio
来源:https://stackoverflow.com/questions/20414504/how-do-i-replicate-a-t-tab-space-in-html