Style sheets
Create site5 by copying site4.
- /cms
- ...
- site4
- site5
In this chapter, we are going to organize CSS files and see how style sheets can be added dynamically to a document.
To test the result online, enter http://www.frasq.org/cms/site5 in the address bar of your navigator.
Create the folder css in site5.
- /cms/site5
- css
Style sheets are added by the view head.phtml which generates the <head> section of a document.
- <?php if (true): ?>
- <link href="<?php echo $base_path; ?>/css/zero.css" rel="stylesheet" type="text/css" media="screen" />
- <?php endif; ?>
- <link href="<?php echo $base_path; ?>/css/screen.css" rel="stylesheet" type="text/css" media="screen" />
- <link href="<?php echo $base_path; ?>/css/theme.css" rel="stylesheet" type="text/css" media="screen" />
- <link href="<?php echo $base_path; ?>/css/print.css" rel="stylesheet" type="text/css" media="print" />
- <?php if (isset($stylesheets)): ?>
- <?php foreach ($stylesheets as $css) : ?>
- <link href="<?php echo $base_path; ?>/css/<?php echo $css['name']; ?>.css" rel="stylesheet" type="text/css" media="<?php echo $css['media']; ?>" />
- <?php endforeach; ?>
- <?php endif; ?>
The code starts by including the 4 files zero.css, screen.css, theme.css and print.css, then all the files in the array $stylesheets
which is built dynamically by the function head
defined in head.php:
- case 'stylesheet':
- $name=$args[0];
- $media=isset($args[1]) ? $args[1] : 'all';
- if (!isset($head['stylesheets'])) {
- $head['stylesheets'] = array(compact('name', 'media'));
- }
- else {
- foreach ($head['stylesheets'] as $css) {
- if ($css['name'] == $name) {
- break 2;
- }
- }
- $head['stylesheets'][]=compact('name', 'media');
- }
- break;
EXAMPLE: Calling head('stylesheet', 'php', 'screen')
adds the file php.css associated to the media screen to the list of style sheets in $head
. Notice that the code is careful not to add the same file twice.
Copy all the style sheets files in the folder css.
- /cms/site5
- css
- zero.css
- screen.css
- theme.css
- print.css
- css
- html, body, div, span, object, iframe,
- h1, h2, h3, h4, h5, h6, p, blockquote, pre,
- a, abbr, acronym, address, code,
- del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
- fieldset, form, label, legend,
- table, caption, tbody, tfoot, thead, tr, th, td
- {font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}
- caption, th, td {text-align:left;font-weight:400;}
- blockquote:before, blockquote:after, q:before, q:after {content:"";}
- blockquote, q {quotes:"" "";}
- h1 {font-size:170%;}
- h2 {font-size:160%;line-height:130%;}
- h3 {font-size:140%;}
- h4 {font-size:110%;}
- h5 {font-size:110%;}
- h6 {font-size:100%;}
- ul, pre {margin-top:1em;}
- form {margin:0;}
- input, select {vertical-align:middle;}
- p, dl, multicol {margin:1em 0;}
- a img {border:0;vertical-align:middle;margin:0;}
- a:link, a:visited {text-decoration:none;}
- a:hover {text-decoration:underline;}
zero.css tries to normalize some properties which navigators set differently by default.
- body {width:960px;margin:5px 0 0 50px;}
- body {font-family:sans-serif;font-size:medium;}
- h1, h2, h3, h4, h5, h6, label, caption, #rate-it legend {font-family:Helvetica, "Helvetica Neue", Arial, sans-serif;}
- code {font-family:"Courier New", Courier, monospace;}
- pre code {font-size:10pt;}
- h1,h2,h3,h4,h5,h6 {font-weight:bold;}
- h1,h2,h3,h4,h5,h6 {margin:1em 0 0.5em 0;}
- label, legend {font-size:80%;}
- table th, table td {padding:5px;margin:0;}
- form p {vertical-align:top;}
- input {margin-top:0;margin-bottom:0;vertical-align:middle;}
- img {vertical-align:middle;}
- .hidden {display:none;}
- .invisible {visibility:hidden;}
- .left {float:left;margin:0 1em 0 0;}
- .right {float:right;margin:0 0 0 1em;}
- .x-large {font-size:x-large;}
- .large {font-size:large;}
- .medium {font-size:medium;}
- .small {font-size:small;}
- .x-small {font-size:x-small;}
- .smaller {font-size:smaller;}
- .larger {font-size:larger;}
- .emphasis {font-style:italic;}
- .superscript {vertical-align:super;}
- .aleft {text-align:left;}
- .aright {text-align:right;}
- .acenter {text-align:center;}
- #content {margin:1em 0 1em 0;clear:both;}
- #footer {font-size:small;margin:2em 0 1em 0;clear:both;}
- #footer p {margin: 0.5em 0 0.5em 0;}
- #footer p img {vertical-align:middle;}
screen.css defines properties which are identical for all the site's themes.
- a:link, a:visited {color:#ec902d;}
- a:hover {color:#2c430d;}
- body {color:#333333;font-family:Verdana, sans-serif;font-size:100%;}
- h1,h2,h3 {color:#aec14e;}
- h4 {color:#aec14e;}
- h5 {color:#df6f6f;}
- h6 {color:#666666;}
- h4 a:link {color:#aec14e;text-decoration:none;}
- h4 a:hover {color:#ec902d;text-decoration:none;}
- h3 {line-height:24px;background:transparent url(../images/heading.png) no-repeat;text-indent:30px;margin:0 0 0.5em 0;}
- pre {border:1px dashed #808080;padding:3px;background-color:#ffffe0;color:#333333;overflow:auto;}
theme.css adds properties which are specific to a theme.
Add the decoration for the <h3>
titles in the folder images:
- /cms/site5
- images
- heading.png
- images
- * {background-color:white !important;}
- body {line-height:1.5;font-family:inherit;color:#000;background:none;font-size:10pt;}
- .container {background:none;}
- hr {background:#ccc;color:#ccc;width:100%;height:2px;margin:2em 0;padding:0;border:none;}
- hr.space {background:#fff;color:#fff;}
- h1, h2, h3, h4, h5, h6 {font-family:inherit}
- code {font:.9em "Courier New", Courier, monospace;}
- a img {border:none;}
- p img.top {margin-top:0;}
- blockquote {margin:1.5em;padding:1em;font-style:italic;font-size:.9em;}
- a {color:#fff;text-decoration:none;}
- h1, h2, h3, h4, h5, h6 {page-break-after:avoid;page-break-inside:avoid}
- blockquote, table, pre {page-break-inside:avoid}
- ul, ol, dl {page-break-before:avoid}
- img {page-break-inside:avoid; page-break-after:avoid; float:none}
- .pagebreak {page-break-before:avoid}
- .hidden {display:none;}
- .noprint {display:none;}
print.css tries to make printing pages on paper more readable.
Comments