Example 3: Now consider another variant of the case a little more complex.Suppose that the same logo of the Weblinks is smaller than the others.
<style type="text/css">
<?php
// Same code as above, as a reference
if ($option == 'com_frontpage') {
$logo = 'url(logo-portada.jpg) #ffffff no-repeat;';
} else if ($option == 'com_weblinks') {
$logo = 'url(logo-enlaces.jpg) #ffffff no-repeat;';
}else{ // "De lo contrario..."
$logo = 'url(logo-generico.jpg) #ffffff no-repeat;';
}
//Here we start with size configuration of logos
if ($option == 'com_weblinks') { // "Si estamos en los Enlaces Web"
$logo_ancho = '400px'; // "Éste será el ancho del logo"
$logo_alto = '200px'; // "y éste el alto"
}else{ // "De lo contrario..."
$logo_ancho = '300px'; // "Éste será el ancho del logo"
$logo_alto = '150px'; // "y éste el alto"
}
$css = '
div#cabezal {
background: '. $logo .';
width: '. $logo_ancho .';
height: '. $logo_alto .';
}
';
$css = str_replace('url(' , 'url(' .$rutaimg , $css);
echo $css;
?>
</style>
Dynamic semantic?There is now a factor that should be taken in mind and internalize as a principle.In the modern web design there is a very simple and foolproof rule: HTML is responsible for all matters relating to the structure and CSS for everything related to the presentation.
Since the CSS also became a dynamic, this rule should remain in force: PHP code that controls the structure will be written into the HTML, and PHP which controls the presentation will be written into the CSS style sheet.
This not only sounds logical, but it will help us to better organize our work, both in the location/provision of the code as in problem solving, as well as making it easier to search for and identification of potential problems (ranging from simple layer poorly placed, to errors of various kinds).
Building a dynamic web is a complicated process itself, because the site is not composed of files, all information, links, sections, and other categories based as text in a database.If you want to customize a website up in these conditions, it is necessary to find a more synergistic and organized use to the engine that controls the dynamic stuff, PHP.
Just imagine the possibilities of what you can achieve.For a sample of what we mentioned, see the following example:
Example 4: Here we are going to rotate 3 images of a header in random order.The rotation would occur with each page refresh, while preserving the same class all the time.All this using only dynamic CSS:
<style type="text/css">
<?php
$imagenes = array("imagen1.jpg","imagen2.jpg","imagen3.jpg");
$resultado = $imagenes[rand(0, count($imagenes)-1)];
$css = '
div#cabezal {
background: url('. $resultado .') no-repeat;
}
';
$css = str_replace('url(' , 'url(' .$rutaimg , $css);
echo $css;
?>
</style>
Example 5: Now lets add more seasoning at the same event.Suppose that when the Homepage show a set of rotating logos, the Content section show anotherset, while Weblinks section will have a different one:
<style type="text/css">
<?php
if ($option == 'com_frontpage') {
$imagenes = array("imagen1.jpg","imagen2.jpg","imagen3.jpg");
} elseif ($option == 'com_content') {
$imagenes = array("imagen4.jpg","imagen5.jpg","imagen6.jpg");
} elseif ($option == 'com_weblinks') {
$imagenes = array("imagen7.jpg","imagen8.jpg","imagen9.jpg");
}
$resultado = $imagenes[rand(0, count($imagenes)-1)];
$css ='
/* Of course, CSS part remains without change */
div#cabezal {
background: url('. $resultado .') no-repeat;
}
';
$css = str_replace('url(' , 'url(' .$rutaimg , $css);
echo $css;
?>
</style>
It is perfectly possible to do this work in the dynamic HTML and adding a few more styles.The above procedure only reflects a style in the results of CSS, which changes depending on the section where the user.It is very important to allocate portions of the code in the correct file, and distribute the pieces in a logical way.
Previously it was mentioned that the work could be better organized following the same principle that governs the semantic web design: Structure for HTML and CSS for presentation.Certainly it is possible to do more with dynamic CSS, but after a few test scenarios that force capability and original purpose of CSS, I could see that it is better to keep things within this principle, otherwise they will cause more problems those resolve.
Therefore it is better to spread the load, because one of the main reward is the fact to liberate much of the responsibility to HTML part (index.php of our template).Previously it was necessary to create new classes, leaving the entire burden dynamic to HTML, while the CSS remained static and accumulating eternal lines to compensate for the uneven playing field.
ConclusionSo far we have seen to PHP doing more productive work that a mosLoadModules or other proper syntax of a common template.Carrying styles management to a dynamic character, we have made significant simplification of several aspects which have so far proved a headache.The PHP + CSS combination implies the existence of a wealth of resources, so long as to consider a large and unexpected door open with a lot to build on.
The semantics of the code also contributes -though not itself- to synergistically enhance the quality of the project.In the field we work, synergy is to achieve better results with the lowest possible use of resources.Using it with skill and creativity, surely find more rapid and simplified ways to achieve the same goals that previously required a few extra steps.
As a Web designer it is necessary to have clear what level of coverage you need from your resources and prepare for new skills, which determines the difficulty the same goals that you propose to complete.The explained method is not astronautical science or nuclear engineering.
All that is required is our willingness to acknowledge that there is an ingredient rather than pure HTML and CSS, which will help us to develop sites more impressive, with high levels of personalization and comprehensive quality. Is that now you find it difficult not to want to try?.