Inserting a variable in a stylesheet.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug Laidlaw

    Inserting a variable in a stylesheet.

    I am in the process of converting a page with nested tables to CSS. The
    current page is at http://www.douglaidlaw.net./boykett/history.html. So
    far, it is using a page-wide stylesheet to set fonts only.

    I want this page to be followed by others with identical layout for
    successive "chapters." In each page, I would like a different image to
    replace the overworked silhouette. For example, in the next page, I would
    like to have photos of Thomas' office building, then and now. So they will
    be not only different from Page 1, but different from each other.

    How can I handle that with a stylesheet? Rather than do away with tables
    altogether, as a first stage, I would prefer to move the table structure to
    a site-wide stylesheet. All pages use the same basic structure. I would
    need something like IMG1 and IMG2 in the stylesheet, and the URLs stated in
    the individual page.

    Thanks,

    Doug
    --
    Registered Linux User No. 277548. My true email address has hotkey for
    myaccess.
    Never let your sense of morals get in the way of doing what's right.
    - Isaac Asimov.

  • Martin Honnen

    #2
    Re: Inserting a variable in a stylesheet.


    Doug Laidlaw wrote:
    [color=blue]
    > In each page, I would like a different image to
    > replace the overworked silhouette.[/color]
    [color=blue]
    > How can I handle that with a stylesheet?[/color]

    If you have server-side scripting (e.g. PHP or Perl or JSP or ASP)
    available then you could generate stylesheets dynamically, for instance
    passing in the image URL in the query string e.g.
    <link rel="stylesheet "
    type="text/css"
    href="styleshee t.php?img=image 1.gif">
    and then generating the CSS you want to serve.

    There is nothing you could do directly in a static stylesheet as CSS
    does not allow you to have variables which a user agent would substitute
    as needed.

    --

    Martin Honnen

    Comment

    • Andy Dingley

      #3
      Re: Inserting a variable in a stylesheet.

      On Thu, 12 Jan 2006 14:52:28 +1100, Doug Laidlaw
      <laidlaws@myacc ess.com.au> wrote:
      [color=blue]
      >I want this page to be followed by others with identical layout for
      >successive "chapters." In each page, I would like a different image to
      >replace the overworked silhouette.[/color]

      You need to apply different fragments of a stylesheet to each group of
      pages.

      There are two ways to do this - take your pick.

      One is to have n+1 stylesheets. Each page links in the "common"
      stylesheet, then after that links in the appropriate "chapter"
      stylesheet. The chapter stylesheet has only the chapter-specific changes
      in it (for robustness, these over-write a safe default that's in the
      common stylesheet anyway).

      The other way is to have one stylesheet and to give each page a class on
      the <body> tag of "chapter1" etc. Then use this in a selector in a
      repeated group of similar rules in the common stylesheeet, changign the
      value as necessary.

      Don't do dynamic things - this isn't a dynamic site. It's easier to do
      it as a one-off publishing task, rather than a repeated page-serving
      task.

      Comment

      • Doug Laidlaw

        #4
        Re: Inserting a variable in a stylesheet.

        Martin Honnen wrote:
        [color=blue]
        >
        > Doug Laidlaw wrote:
        >[color=green]
        >> In each page, I would like a different image to
        >> replace the overworked silhouette.[/color]
        >[color=green]
        >> How can I handle that with a stylesheet?[/color]
        >
        > If you have server-side scripting (e.g. PHP or Perl or JSP or ASP)
        > available then you could generate stylesheets dynamically, for instance
        > passing in the image URL in the query string e.g.
        > <link rel="stylesheet "
        > type="text/css"
        > href="styleshee t.php?img=image 1.gif">
        > and then generating the CSS you want to serve.
        >
        > There is nothing you could do directly in a static stylesheet as CSS
        > does not allow you to have variables which a user agent would substitute
        > as needed.
        >[/color]

        Thank you, Martin. Yes, I do have PHP. The family tree program itself is
        written in PHP. I suppose that I could just leave the image to be put
        there by HTML, in a similar fashion to the text block, but I haven't
        thought it through.

        Doug.
        --
        Registered Linux User No. 277548. My true email address has hotkey for
        myaccess.
        No man was ever endowed with a right without being at the same time saddled
        with a responsibility.
        - Gerald W. Johnson.

        Comment

        Working...