I’m still banging on that HTML/CSS tutorial – started out as a quick “how-to” for a class and is becoming something much larger, maybe even something I can market for use as part of a design curriculum once it’s whipped into shape.
The thing is focused on “modern best practices,” and as such, I figure I’d better use best practices in the code, else I look like a lug. Here’s the question:
Don’t forget three related element tags; kbd, samp, and var. The kbd and samp are for indicating interactive dialogues, but var might be used nested within any of the others. E.g.
<pre>
<samp>koko:/home/gt#</samp> <kbd>apt-get <var>upgrade</var></kbd>
<samp>Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
cups grub mysql-server
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
koko:/home/gt#</samp> <kbd>exit</kbd>
<samp>exit</samp></pre>
=============
samp, kbd, var, code {
font-family: monospace; /*the usual default*/
}
kbd {
font-weight: bold;
}
var {
color: blue;
}
I agree. For what you’re doing, it sounds like code is the most relevant, and depending on what you’re doing, maybe var (more useful for marking up PHP, C#, Java, etc. However, you can you kbd elements to indicate actual user input that should be submitted to a particular application and samp elements to indicate the application output for that input. Code is the most widely applicable and I use it a lot on my beta website when I explain a new procedure to markup code for the new feature.
Yep. They serve somewhat different functions. For what I’m doing, CODE works quite well. I am, however, using another styled class to present HTML and CSS code in a larger, styled block. I think the question of using PRE in that case will be identical to the question about CODE I asked earlier. I think I’m going to make that change also.
Code is a phrase entity, and is inline. It does nothing special other than the usual default to a monospace font family. You are probably remembering it not keeping your formatting. Fortunately, as an inline, it belongs in a block container, and pre fulfills both functions.
It may not be the child of <p>. It may be the child of <body>, <div>, or <li>, for example, or any element that may contain a %block or %flow entity. Like most %block elements, it may stand alone.
You could theoretically use a div in stead of the pre and style it using CSS, but the pre does have some semantic significance as well (it indicates that the whitespace entered has significance for the contents).
The pre is structural and says these contents’ structure is important. It says nothing about what the content is. The code tag indicates what that content is. As in my example above, that could just as well be some other inline element that bestows a semantic value on the content.
Because pre indicates preformatted text, while code indicates a fragment of computer code. They are two completely different aspects of a snippet of code.
Your question is analogous with this one: ‘why would you need to use ABBR inside a P block?’
Tommy, since I’ve styled my PRE and CODE elements to appear entirely differently, if I use them together, they will conflict most hideously. Any suggestions? I don’t want to use a class on the standalone PRE formatted text if I don’t have to, but I can if needed.