Generating CSS

Uray Web Library (UWeb)

Uray M. János © 2021-2024

When an HTML page is generated using UWeb, it will use certain CSS classes defined by UWeb. These CSS definitions must be available, otherwise the page will not look correctly. This documentation page describes the various ways to make these CSS codes available.

The simplest way to do this is to use one of the pregenerated CSS files. A more flexible solution is to generate a custom CSS file using UWeb.

Contents

Contents

1. Pregenerated CSS files

2. Generating CSS files

2.1. Header comment

2.1.1. $title

2.1.2. $project

2.1.3. $author

2.1.4. $date

2.2. basic.css.php

2.2.1. $color

2.2.2. $bgcolor

2.2.3. $bgcolor2

2.2.4. $sel_color, $sel_bgcolor

2.2.5. $has_link

2.2.6. $link_color

2.2.7. $has_title

2.2.8. $title_color

2.2.9. $subtitle_color

2.2.10. $has_headings

2.2.11. $has_toc

2.2.12. $h_color

2.2.13. $has_author

2.2.14. $has_small

2.2.15. $has_link_collection

2.2.16. $has_lists

2.2.17. $has_code

2.2.18. $code_color

2.2.19. $has_table_grid

2.2.20. $has_framed_box

2.2.21. $has_hr

2.2.22. $has_full_width_img

2.2.23. $has_pale

2.2.24. $pale_color

2.2.25. $has_error

2.2.26. $error_color

2.2.27. $has_menu

2.2.28. $has_footer

2.2.29. $has_bottom_space

2.3. active.css.php

2.3.1. $disabled_color

2.3.2. $highlight_color

2.3.3. $has_button

2.3.4. $button_bgcolor

2.3.5. $button_border_color

2.3.6. $button_disabled_color

2.3.7. $button_highlight_color

2.3.8. $button_loading_color

2.3.9. $has_button_image

2.3.10. $has_input

2.3.11. $input_bgcolor

2.3.12. $input_color

2.3.13. $input_border_color

2.3.14. $input_disabled_bgcolor

2.3.15. $input_disabled_color

2.3.16. $input_disabled_border_color

2.3.17. $has_checkbox

2.3.18. $has_input_lines

2.3.19. $has_options

2.3.20. $has_tooltip

2.3.21. $qmark_color

2.3.22. $has_marks

2.3.23. $mark_error_color

2.3.24. $mark_info_color

2.3.25. $mark_success_color

2.3.26. $mark_alert_color

2.3.27. $has_popup

2.3.28. $has_dropdown

2.3.29. $has_tabbed

2.4. Adding custom CSS

2.4.1. open()

2.4.2. close()

2.4.3. title()

2.4.4. big_title()

2.4.5. title_opt()

2.4.6. generate()

1. Pregenerated CSS files

Two CSS files are generated automatically by UWeb:

The intended way to use these files is to copy (or better, symlink) the selected CSS file next to the HTML file (renamed to e.g. uweb.css for clarity), and then set basic_page::css() to this file. (This is how these documentation pages use basic.css.)

2. Generating CSS files

There is a more flexible solution than using one of the pregenerated CSS files. Webpages can generate their own CSS files using the tools provided by UWeb. In this way, they can select exactly what styles they need, so the clients are not overloaded with unused CSS definitions (as they could be with all.css), and these styles can be customized, e.g. using different colors. Webpages can also add new CSS definitions to the same generated file (under the same license as UWeb, i.e. GPLv3), which may improve load speed, compared to multiple separate CSS files.

A CSS file can be generated by the following steps:

Here is a simple example:

<?php
// Configure the header comment
$project = "Some Website";
$author = "Uray M. János";
$date = "2024";

// Configure and include the basic styles
$bgcolor = "#000";
$color = "#CCE";
$link_color = [["#C82", "#EA3"], ["#A74", "#C95"]];
$title_color = "#D22";
$has_toc = false;
$has_menu = $has_footer = true;
require_once __DIR__."/uweb/basic.css.php";

// Configure and include the styles for dynamic elements (optionally)
$has_button_image = true;
$has_input = false;
require_once __DIR__."/uweb/active.css.php";

// Define some custom styles (optionally)
big_title("Some Website styles");
open();?><style>
   .some-class {
      text-align: center;
   }
</style><?php close();

// Actually generate the content
generate();

2.1. Header comment

The generated CSS file will start with a comment similar to this:

/*
   Stylesheet -- Some Website
   Generated by the Uray Web Library (UWeb).
   License: GPLv3 or later, see ...
   Uray M. János © 2024
*/

Its content can be customized by the following variables.

2.1.1. $title

The title of the CSS file in the header comment.

Default value: "Stylesheet"

2.1.2. $project

The title of the project name (website name) in the header comment, e.g. "Some Website".

This variable is required.

2.1.3. $author

The author of the project in the header comment.

Default value: "Uray M. János"

2.1.4. $date

The copyright date of the project in the header comment, e.g. "2024" or "2020-2024".

2.2. basic.css.php

This file contains the basic styles and tools for generating a CSS file. It must be included in the generating PHP file.

The following variables can be used to configure these basic styles (e.g. turn them on/off, or customize them).

The default basic.css (used by e.g. this documentation) is generated from the default values of all these settings (except where noted).

2.2.1. $color

Text color of the website, in CSS format (e.g. "#000" or "black").

2.2.2. $bgcolor

Background color of the website, in CSS format (e.g. "#FFF" or "white").

2.2.3. $bgcolor2

The alternative background color for certain special areas, e.g. the title box of the page (see the top of this documentation page), or popup dialogs.

Default value: $bgcolor if it was redefined

2.2.4. $sel_color, $sel_bgcolor

Color of selection (text and background color), i.e. parts of the page that are selected by the user.

Default value: $bgcolor and $color (i.e. inverse colors)

Include the styles for HTML links (<a href='...'>).

Default value: true

Color of HTML links (<a href='...'>).

It is either a CSS color value (string), an array of color values, or an array of arrays of color values, defining the colors for the various link types. More precisely, the following combinations are allowed:

2.2.7. $has_title

Include styles for the page title, i.e. <p class='title'> and <div class='title-box'>.

This is required by basic_page::make_title().

Default value: true

2.2.8. $title_color

Color of the title, i.e. <p class='title'> (e.g. inside basic_page::make_title()).

Default value: $color if it was redefined, and red in the default style

2.2.9. $subtitle_color

Color of the subtitle, i.e. <p class='subtitle'> (e.g. inside basic_page::make_title()).

Default value: $title_color

2.2.10. $has_headings

Include styles for the HTML headings: <h1>, <h2>, …, <h6>.

Default value: true

2.2.11. $has_toc

Include styles for the table of contents, generated by print_toc_content().

Default value: $has_headings (which is true by default)

2.2.12. $h_color

Colors of the HTML headings: <h1>, <h2>, …, <h6>.

It is either a single CSS color value (for all headings), or an array of 6 color values (index 0 for <h1>, 1 for <h2> etc.).

Default value: $title_color if it was redefined

2.2.13. $has_author

Include style for the author, i.e. <p class='author'>.

This style can be used inside basic_page::make_title() (e.g. see the title box on the top of this documentation).

Default value: false (but true in basic.css)

2.2.14. $has_small

Include styles for smaller text: <p class='info'>, <span class='info'>, <a class='small'>.

Default value: true

Include style for a collection of links in a line:

<p class='links'>
   <a href='page1.html'>Link 1</a>
   <a href='page2.html'>Link 2</a>
   <a href='page3.html'>Link 3</a>
</p>

Default value: false

2.2.16. $has_lists

Include styles for HTML lists: <ul> and <ol>.

Default value: true

2.2.17. $has_code

Include styles for fixed-width text (e.g. for program code): <code> and <pre>.

Default value: true

2.2.18. $code_color

Color of fixed-width text: <code> and <pre>.

Default value: $color if it was redefined

2.2.19. $has_table_grid

Include style for table with grid: <table class='grid'>. (By default, <table> has no visible lines.)

Default value: true

2.2.20. $has_framed_box

Include style for a framed box with slightly different background: <div class='framed-box'>. (It looks similar to the title box at the top of this page, but it is not specifically for titles.)

Default value: false

2.2.21. $has_hr

Include style for a horizontal rule: <hr/>.

Default value: true

2.2.22. $has_full_width_img

Include style for a full-width responsive image: <img class='full-width'/>. It will be displayed in its original size if it fits, otherwise it will be shrinked down exactly to the available width.

Default value: false

2.2.23. $has_pale

Include style for pale text (i.e. text with less intensive color): class='pale'.

Default value: false – but true if $pale_color is redefined

2.2.24. $pale_color

Color of pale text.

Default value: a color halfway between the default $color and the default $bgcolor

2.2.25. $has_error

Include style for an error page (used by error_message), and a style for error messages: class='error-message' (which, by default, makes the text red and italic).

Default value: false – but true if $error_color is redefined

2.2.26. $error_color

Color of error messages.

Default value: red

2.2.27. $has_menu

Include style for the menu, used by basic_menu.

Default value: false

Include style for the footer, used by basic_footer.

Default value: false

2.2.29. $has_bottom_space

Include style for basic_page::bottom_space().

Default value: false (but true in basic.css)

2.3. active.css.php

This file contains styles for the dynamic functionalities of UWeb (e.g. buttons, input fields etc.), see js.html and active.php.

The following variables can be used to configure these styles.

2.3.1. $disabled_color

Common color for disabled buttons and input fields. Disabled means that they cannot be interacted with by the user.

Default value: $pale_color

Note: it can be customized for buttons ($button_disabled_color) and input fields ($input_disabled_color) separately.

2.3.2. $highlight_color

Common color for highlighted elements, e.g. submit buttons for changed forms (if data-highlight was set) and alerts.

Default value: $title_color

2.3.3. $has_button

Include styles for pushable buttons (<button>).

Default value: true

2.3.4. $button_bgcolor

Background color of buttons.

Default value: $bgcolor2

2.3.5. $button_border_color

Border color of buttons.

The value is an array of [$dark, $light], containing the two color shades of the 3D-looking frame.

2.3.6. $button_disabled_color

Text color of disabled buttons (<button disabled>).

Default value: $disabled_color

2.3.7. $button_highlight_color

Text color of highlighted buttons, which can be set by class='highlight', or caused by the form attribute data-highlight.

Default value: $highlight_color

2.3.8. $button_loading_color

Color of the ellipsis (…) on buttons, which is shown when its action takes too much time (or it can also be set by class='loading').

Default value: the text color of the button

2.3.9. $has_button_image

Include styles for image-based buttons (see button_image()).

Default value: false

2.3.10. $has_input

Include styles for input fields: <input/>, <textarea> and <select>.

Default value: true

2.3.11. $input_bgcolor

Background color of input fields.

Default value: white if $bgcolor was redefined

2.3.12. $input_color

Text color of input fields.

Default value: inherit (i.e. use the current text color) if $color was redefined

2.3.13. $input_border_color

Border color of input fields.

The value is an array of [$dark, $light], containing the two color shades of the 3D-looking frame.

2.3.14. $input_disabled_bgcolor

Background color of disabled input fields (e.g. <input type='text' disabled/>).

Default value: $bgcolor

2.3.15. $input_disabled_color

Text color of disabled input fields (e.g. <input type='text' disabled/>).

Default value: $disabled_color

2.3.16. $input_disabled_border_color

Border color of disabled input fields (e.g. <input type='text' disabled/>).

The value is an array of [$dark, $light], containing the two color shades of the 3D-looking frame.

Default value: $input_border_color

2.3.17. $has_checkbox

Include styles for checkboxes (<input type='checkbox'/>) and radio buttons (<input type='radio'/>).

Default value: $has_input

2.3.18. $has_input_lines

Include styles for aligned input lines, see input_line(). For example:

<div class='input-lines'>
   <div>
      <div> Username: </div>
      <div> <input type='text'/> </div>
   </div>
   <div>
      <div> Password: </div>
      <div> <input type='password'/> </div>
   </div>
</div>

Default value: false

2.3.19. $has_options

Include styles for checkbox containers (class='options', class='options-inline'), for example:

<div class='options'>
   <label> <input type='checkbox'/> First  </label>
   <label> <input type='checkbox'/> Second </label>
   <label> <input type='checkbox'/> Third  </label>
</div>

Default value: false

2.3.20. $has_tooltip

Include styles for popup tooltips (data-tip). See also info_text() and qmark().

Note: tooltips also require $has_tooltip in JavaScript.

Default value: false

2.3.21. $qmark_color

Color of the tooltip question marks generated by qmark().

Default value: the text color

2.3.22. $has_marks

Include styles for form marks, see show_mark(), <!mark> and input_error().

Default value: true

2.3.23. $mark_error_color

Color of the exclamation mark (!) in the form mark with type='error'.

Default value: $highlight_color

2.3.24. $mark_info_color

Color of the exclamation mark (!) in the form mark with type='info'.

Default value: the text color

2.3.25. $mark_success_color

Color of the checkmark (✔) in the form mark with type='success'.

Default value: green

2.3.26. $mark_alert_color

Text color in the form mark with type='alert'.

Default value: $highlight_color

2.3.27. $has_popup

Include styles for popup dialog boxes, see show_popup() and <!popup>.

Default value: true

2.3.28. $has_dropdown

Include styles for dropdown boxes, see show_dropdown(), dropdown_menu() and data-action='dropdown'.

Note: dropdowns also require $has_dropdown in JavaScript.

Default value: false

2.3.29. $has_tabbed

Include styles for multi-tab content (class='tabbed-head' and class='tabbed-body'), see tabbed().

Note: this feature also requires $has_tabbed in JavaScript.

Default value: false

2.4. Adding custom CSS

Custom CSS rules can be inserted into the generated CSS file like this:

open();?><style>
   .some-class {
      text-align: center;
   }
</style><?php close();

The CSS content must be surrounded by the following code:

The CSS content can contain PHP code, using any of the variables described above, e.g.:

open();?><style>
   .some-class {
      color: <?=$error_color;?>;
   }
</style><?php close();

The custom CSS content may be split into any number of blocks by open()/close() pairs. Adjacent blocks will be separated by empty lines in the generated CSS file.

The generated CSS blocks may be separated by comments for better readability, by using the functions title(), big_title() and title_opt().

Note that since these custom CSS styles will be added to the same file as UWeb's CSS, they will share the same license (GPLv3). If this is not desired, the custom CSS must be put into a separate file.

2.4.1. open()
function open ($title = null);

Open a custom CSS block. It must be closed by a subsequent close().

$title: if given, the block is preceded by the given comment. It is equivalent to calling title($title) before open().

2.4.2. close()
function close ();

Close the custom CSS block opened by the last open().

2.4.3. title()
function title ($title);

Insert a title comment to the generated CSS file. It can be used to separate custom CSS blocks.

For example, title("Button styles") generates the following comment (separated by an empty line from both adjacent blocks):

/* Button styles */
2.4.4. big_title()
function big_title ($title);

Insert a major title comment to the generated CSS file. This is more noticable than title(), so it can be used for higher-level separation.

For example, big_title("Dynamic elements") generates the following comment (separated by two empty lines from the previous block and one empty line from the next one):

/* Dynamic elements */
/* ---------------- */
2.4.5. title_opt()
function title_opt ($title);

Insert a title comment like title(), but only if there is any CSS block following this function call before the next title.

This can be useful if the subsequent CSS blocks appear conditionally, e.g. inside if statements. Then this title will only appear if those blocks are present.

2.4.6. generate()
function generate ();

Actually generate the CSS code.

This must be the last statement in the PHP file that generates the CSS file. Without this, no output is produced.