Current Articles
  Archived Articles
  TECHS Articles
  Current Projects
  About Us
You are not logged in.

Please either Login or create a New Account.
Custom RSS

Note: this links is the RSS feed for the current filters shown at the top of the page. For an RSS feed for all articles in this community, click here
  Remove both filters (2)
Tag
CSS (7)
Tag
examples (4)
Recently I did a little study to investigate options for a solid printing foundation from a website.  I did a lot of research and had fun investigating the w3c's css standard for alternate media types.  Although I came to the conclusion that for rock solid printing, there is no alternative to PDF, I learned that there is considerable browser support for print media.  With that said. the most valuable concept I gathered from my research was that it is quite easy using css to make an entire site much more printer-friendly. 
Let me give my definition of printer-friendly.  The ultimate would be complete control of the margins on the page and placement of all objects on the page and meaningful page breaks.  Because of different browser implementations of the print media standard, this is a complete pipe dream.  With that said, I consider printer-friendly to be a way to print the main content of a web page without cluttering up the printed page with web navigation or cute stuff.   
Ok, enough yacking... 

There are several ways to accomplish a different css application to page elements based on the media type.  One can actually make 2 distinct .css files, one for web and one for print.  Then in the page head create the link to each one.  Another method is to include a block of css in the existing css file and enclose it in a @media print{} style rule.  Either way, browsers are smart enough to use the correct css for the media it is trying to present.  I found the best way to test this is by using the print preview option available in most modern browsers. 

Here is an example.  For a simple page with a menu block on the left and a content area on the right, we might have an html block that looks like this...

<div class=page>
    <div class = menu> Menuy things </div>
    <div class = content>  Content Stuff </div>
</div>

A typical css file might set the layout for the menu to be on the left and the content in the middle using a style like this...

.page {width:500px; }
.menu {width:200px; float:left; }
.content { width:300px; }

But by adding another set of styles we can hide the menu for print media like this...


@media print
{
.page {width:7in; }
.menu {display:none; }
.content { width:7in; }
}

This style will only be applied for printing.  The main differences are that the menu class has display:none; which hides that block and I use inches as units rather than pixels.  I like to specify the width to avoid things that extend off the right hand of the printed page.  Again, double check by using the print preview feature in your browser.

Try it out yourself with this code.

Enjoy


Tags: CSSexamples



Here is a sample project that can be used as an example for the TECHS class.

http://www.caffeinatedcoding.org/examples/todo/todo.htm

When you enter text into the textbox and once you hit enter(firefox only) or tab, then the page starts a list with the text that was entered into the textbox.  If you don't like the item in the list, click on the text and it is removed.

This is kindof a dumb thing, but it demonstrates how html, CSS, and Javascript can work together.
Below is the code...

For fun put it into a page on your computer and play with it.  Who cares if you screw it up, you can always come back here and get it again.


<html>
<head>
    <title>To Do List </title>
    <style type="text/css">     
<!--
        .inputbox { width:800px; height:100px; text-align:left; vertical-align:middle;  color:#ffffff; font-size:20pt;}
        .listbox { border:1px; border-style:dashed; background-color:#665533; }
        .list { color: #002277; background-color: #665533; font-family: Corbel, Arial Black, Arial; font-size: 30pt;}
        .listitem {  background-color:#774499; width:90%;}
        .listitem-alt {  background-color:#550077; width:90%; }
        body { background-color:#775500; }
        input { font-family: Corbel, Arial Black, Arial; font-size: 30pt; color:#669944; }
--> 
         </style>
</head>
<body >

    <script language="javascript" type="text/javascript">
  <!--
  var blnAlternate;
  
  function AddItem()
   {
   var lstToDo = document.getElementById("lstToDo");
   var txtItem = document.getElementById("txtAddItem");
   if (txtItem.value != '')
       {
           var lstItem = document.createElement("li");

           if (blnAlternate == true)
         {
                   lstItem.innerHTML= "<span class='listitem-alt'  onclick=RemoveItem('" + txtItem.value + "')>" + txtItem.value + "</span>" ;
                         blnAlternate = false;
                        }
     else
         {
           lstItem.innerHTML= "<span class='listitem'  onclick=RemoveItem('" + txtItem.value + "')>" + txtItem.value + "</span>" ;
                         blnAlternate = true;
                         };
     
           lstToDo.appendChild(lstItem);
            txtItem.value='';
           focus=txtAddItem;
          
       };
  
   };
   
  
  function RemoveItem(strItem)
  {
      var lstToDo = document.getElementById("lstToDo");
      for (index=0;index<= lstToDo.childNodes.length;index+=1)
      {
      var lstItem = document.createElement("li");
      lstItem = lstToDo.childNodes[index];
     
      if (lstItem.innerHTML.indexOf(strItem) > 0)
          {
              lstToDo.removeChild(lstItem);
          };
      };
  }
  //-->
    </script>

    <div id="divAddBox" class="inputbox">
    Build your own todo list<br />
    Enter items in the box below and they will appear in the todo list.
        <input type="text" id="txtAddItem" onchange="AddItem()" />
    </div>
    <div id="divList" class="listbox">
        <ol id="lstToDo" class="list"></ol>
    </div>
</body>
</html>

Tags: CSSexamplesHTMLJavascriptTECHS



  1