SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Although, I would just ommit the code tag when using pre. It does nothing above and beyond adding sematic value (if you care).
    And that is the whole bleedin' point with HTML in the first place!
    If you don't care about semantics (which means you don't care about usability or accessibility either, since they depend on semantic correctness) you can just use div elements and IDs and classes to style them with CSS. Or, better yet, stay off the Web!

    Quote Originally Posted by ralph.m View Post
    Hrm, in the past I've had so much trouble getting <code> to work inside <pre> I gave up on it. Even with no whitespace, <pre><code> seems to leave a big gap at the top of the <pre> element. I got sick of trying to work out what was causing it.
    There will be a 'big gap' if you leave a newline after those two tags, like this,
    Code HTML4Strict:
    <pre><code>
    some code here
    going over several lines
    </code></pre>
    That's only to be expected, since the whole purpose of <pre> is to preserve whitespace! So if there shouldn't be a 'semantic' line break at the top of the block you need to write it like this,
    Code HTML4Strict:
    <pre><code>some code here
    going over several lines</code></pre>
    You may also want to set margin-top:0 for <pre> elements, just in case.
    Birnam wood is come to Dunsinane

  2. #27
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Were you aware that pre has a default top and bottom margin?
    Code:
    xmp, pre, plaintext {
      display: block;
      font-family: -moz-fixed;
      white-space: pre;
      margin: 1em 0;
    }
    See file:///[path to Firefox]/res/html.css for Firefox's take on the matter.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  3. #28
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    There will be a 'big gap' if you leave a newline after those two tags, like this,
    Code HTML4Strict:
    <pre><code>
    some code here
    going over several lines
    </code></pre>
    Thanks for that suggestions Tommy and Gary. I did actually remove all newlines and still got the same behavior—even with margin: 0 on the <pre>.

    However, I will have another look at this, as I was ignorant of the semantic importance of <code> within <pre>.
    Last edited by ralph.m; Apr 5, 2010 at 01:30. Reason: clafirication (?)

  4. #29
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Huh, don't get it. I tried it this time (a few years later) and it worked fine. Dunno, maybe I've learned something.

    Off Topic:

    (Hmm, what happened to Eric's post?)

  5. #30
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Since I've gone back to working 15 hours a day (ugh), I haven't had a chance to incorporate the <pre><code> goodness into the site. Therefore I haven't had a chance to see what happens to me with that top/bottom margin, but I'll know not to leave a newline after the opening code.

    Did Eric delete a post? Eric, I sympathize with your drawing the wrath of the Mad Swede but at least your wife doesn't have a crush on him. Count your blessings.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •