Script-based Website Maintenance



CSS macros

Escaping m4

Content in CSS isn't common, but when it occurs, you may need these macros to represent m4-sensitive characters:

define(`APOS',``\0027'')dnl
define(`GRAV',``\0060'')dnl
define(`DOLL',``\0024'')dnl
define(`COMM',``\002C'')dnl

Common selectors

It is difficult to express compactly in CSS that some properties should apply to several rules which all end with some common selectors. This macro generates a comma-separated list of all but its first argument, which follows each item:

define(`CONTEXT_LIST',`$2`'ifelse($1,,,`` '$1')`'ifelse($3,,,
``, 'CONTEXT_LIST(`$1',shift(shift($@)))')')dnl

Colours

These macros generate a complete colour specification from a minimum of two colours (foreground and background):

define(`COLOURS_1', `CONTEXT_LIST(,$1)` {
  color: '$2`;
  background-color: '$3`;
}

'CONTEXT_LIST(``a:link'', $1)` { color: '$4`; }

'CONTEXT_LIST(``a:visited'', $1)` { color: '$5`; }

'CONTEXT_LIST(``a:active'', $1)` { color: '$6`; }

'CONTEXT_LIST(``a:hover'', $1)` { color: '$7`; }

'CONTEXT_LIST(``a:link'', $1)`,
'CONTEXT_LIST(``a:visited'', $1)`,
'CONTEXT_LIST(``a:active'', $1)`,
'CONTEXT_LIST(``a:hover'', $1)` { background-color: transparent; }'')dnl
define(`COLOURS_2',
`COLOURS_1(`$1', `$2', `$3', `$4', `$5', `$6', `ifelse($7,,`$6',`$7')')')dnl
define(`COLOURS_3',
`COLOURS_2(`$1', `$2', `$3', `$4', `$5', `ifelse($6,,`$2',`$6')', `$7')')dnl
define(`COLOURS_4',
`COLOURS_3(`$1', `$2', `$3', `$4', `ifelse($5,,`$4',`$5')', `$6', `$7')')dnl
define(`COLOURS',
`COLOURS_4(`$1', `$2', `$3', `ifelse($4,,`$2',`$4')', `$5', `$6', `$7')')dnl

The arguments are:

  1. a comma-separated list (so it needs an extra pair of quotes around it) of selector sequences for the colour scheme to apply to;

  2. the foreground colour;

  3. the background colour

  4. the unvisited link colour (which defaults to the foreground colour);

  5. the visited link colour (which defaults to the unvisited link colour);

  6. the active link colour (which defaults to the foreground colour);

  7. the hover link colour (which defaults to the active link colour).



Updated: 2007-May-11 16:56 GMT
Contact Steven Simpson

Ĉi tiu paĝo disponeblas ĉi-lingve, laŭ via krozila agordo.