Re: Display Source Code - Color Keywords

Discussion in 'HTML' started by brucie, Jun 23, 2003.

  1. brucie

    brucie Guest

    In post <Xns93A32AF8B7B5Ealexmacmailcom@194.177.210.210>
    Alexander Mac said...

    > I want to present some source code (C++, Java etc) on my page, so I am
    > using <pre><code></code></pre> tags. Is there any way to color the keywords
    > all together? For example, make them appear blue (a CSS maybe?).


    stick it in your <head>

    <style type="text/css">
    code{color:blue;background-color:lime;}
    </style>

    --
    brucie a. blackford. 23/June/2003 11:38:13 am kilo.
    http://loser.brucies.com/
    brucie, Jun 23, 2003
    #1
    1. Advertising

  2. brucie <> wrote:

    > code span{color:blue;background-color:lime;}


    That would work if you won't ever need a span element inside a code
    element for any other purpose. A theoretically more satisfactory,
    though pragmatically clumsy, approach would be

    ..key {color:blue; background:lime;}

    with markup like

    <pre><code class="C"> ... <span class="key">int</span> ...</code></pre>

    There's yet another approach, and some people probably say it's really
    impure. It's based on the fact that _bolding_ is a traditional
    typographic method used for keywords in source code:

    code.C b { color: blue; background: line; font-weight: normal; }

    with concise markup like

    <pre><code class="C"> ... <b>int</b> ...</code></pre>

    The general idea is that when CSS is not in use, the keywords appear in
    bold face, and the style sheet then turns this off and introduces the
    colors. Here <b> and not <strong> is adequate, since we don't really
    want to emphasize the keywords, just make them look different.

    And the probability that you'd ever want to use <b> inside <code> for
    something else is rather minimal.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Jun 23, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew H. Carter

    Re: Display Source Code - Color Keywords

    Andrew H. Carter, Jun 23, 2003, in forum: HTML
    Replies:
    3
    Views:
    1,781
    Andrew H. Carter
    Jun 23, 2003
  2. Jasper Bedaux
    Replies:
    0
    Views:
    898
    Jasper Bedaux
    Jun 23, 2003
  3. RoboHobby
    Replies:
    14
    Views:
    3,211
    John B. Matthews
    Dec 14, 2008
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    377
    Kamaljeet Saini
    Feb 13, 2009
  5. sed_y
    Replies:
    0
    Views:
    996
    sed_y
    Feb 15, 2012
Loading...

Share This Page