M
Mike
I'm having issues. I'm attempting to use <code> and <pre> properly, and
I'm confused. I have to assume that <code> is intended to provide
context, as well as a kind of formatting. However the formatting leaves
something to be desired. It doesn't seem to do much beyond using a
monospace font. It doesn't preserve spacing or line breaks. So, I
learned about using <pre> to keep things neat. But it leaves me
wondering why a tag named "code" is kinda code-snippet-unfriendly? What
am I not getting?
Now given that I want to use <pre>, I nest them together. It appears
that when nesting like so:
<pre>
<code>
...stuff..
</code>
</pre>
....the snippet is surounded by additional line breaks, which I have to
assume is because the <pre> is immediately followed by a line break,
and preserves it? Thus the solution is to do it like so:
<pre><code>
....stuff...
</code></pre>
Experiments with different browsers and editors-with-previews seem to
reinforce this. Is this normal practice?
To add insult to injury: I styled <pre> so that snippets would be
surrounded by borders and had different spacing and size. Looks great.
Really simple stuff. Contrariwise, the same changes to <code> resulted
in a disaster. This leads me to believe that <code> is handled in some
complicated way by browsers. Shouldn't it be mainly a font change?
pre{
width:100%;
padding:1em 0;
overflow:auto;
border-top:1px dotted #333;
border-bottom:1px dotted #333;
}
Thanks, and if you have a recommendation for an antidepressant I could use it.
Mike
I'm confused. I have to assume that <code> is intended to provide
context, as well as a kind of formatting. However the formatting leaves
something to be desired. It doesn't seem to do much beyond using a
monospace font. It doesn't preserve spacing or line breaks. So, I
learned about using <pre> to keep things neat. But it leaves me
wondering why a tag named "code" is kinda code-snippet-unfriendly? What
am I not getting?
Now given that I want to use <pre>, I nest them together. It appears
that when nesting like so:
<pre>
<code>
...stuff..
</code>
</pre>
....the snippet is surounded by additional line breaks, which I have to
assume is because the <pre> is immediately followed by a line break,
and preserves it? Thus the solution is to do it like so:
<pre><code>
....stuff...
</code></pre>
Experiments with different browsers and editors-with-previews seem to
reinforce this. Is this normal practice?
To add insult to injury: I styled <pre> so that snippets would be
surrounded by borders and had different spacing and size. Looks great.
Really simple stuff. Contrariwise, the same changes to <code> resulted
in a disaster. This leads me to believe that <code> is handled in some
complicated way by browsers. Shouldn't it be mainly a font change?
pre{
width:100%;
padding:1em 0;
overflow:auto;
border-top:1px dotted #333;
border-bottom:1px dotted #333;
}
Thanks, and if you have a recommendation for an antidepressant I could use it.
Mike