29
4

4 回答 4

33

For inline code in Javadocs,you should use {@code your-code-here}

See javadoc - {@code text} for more details.

Equivalent to <code>{@literal text}</code>.

Displays text in code font without interpreting the text as HTML markup or nested javadoc tags. ..

于 2013-01-26T14:02:33.233 回答
20

From the W3C on TT.

HTML Reference

The element is a non-standard element.

HTML5 classifies it as a non-conforming feature.

Examples

No, really, don't use it.

And I think that answers the question. Choice of 2 elements, W3C says do not use one of them.

于 2013-01-26T13:27:47.727 回答
7

The code tag is preferred as tt is a font style element and as of HTML 4, styling by style sheets is preferred to font style elements.

于 2013-01-26T13:30:04.157 回答
3

There is little practical difference between code and tt, i.e. software that processes HTML documents treats them the same way: they are by default treated as inline elements, rendered in a browser-dependent monospace font and possibly (depending on browser) in reduced font size. A distinction between them is mostly just theoretic talk. However, some automatic translation software makes a difference, treating code as having non-translatable content.

So there is some advantage in using code, but it is more important that you consider the real implications of either markup. If you don’t want reduced font size, set font-size: 100%. If you don’t want browser’s default monospace, which tends to be Courier New, set font-family.

于 2013-01-26T17:23:07.820 回答