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
Tag
CSS (7)
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



With the demise of Manila, Broken Bow is looking for a different way to provide teachers with a professional web presence.  The probable adoption of web apps like Blackboard and the move toward Web 2.0 apps parcels out many of the reasons for a professional web page to a collection of more specialized systems.  As a result, the ubiquitous "professional web page (every teacher should have one)" is being gradually eviscerated.  There are already schools in Nebraska that are using one-to-one and have completely dropped the use of individual teacher professional web pages.  Our approach will probably be to drop back from "every teacher must have one" to "teachers who want one in addition to what's on Blackboard and Infinite Campus already can have one."

Manila's exit from the scene has a bearing on the development of a different approach.  First, it is driving the timeline for adoption.  It's our intent to drop Manila as of the end of the 2009 Spring semester, and a replacement solution must be in place before then.  Second, Manila's long use in the District has a host of difficulties and complaints that we think can be corrected in a new system.  (It's not that we don't like WordPress, it's just that we don't necessarily agree that every computer user and their dog must blog and that the jury's still out for us.)  Complaints include:

  • I have to remember a separate login ID and password
  • Pages have to be created in Manila, so I have to learn a whole different editing system
  • Drag and drop from Microsoft Word doesn't work, so I wind up having to type things twice
  • Keeping up my web pages is always an additional task, and I don't have the time

Local resources may lend themselves to an elegant solution.  (1) Microsoft IIS is capable of serving out pages from "webshare" folders located in teachers' network home directories, and we are already using it for many other purposes. (2) Microsoft Office (the District's standard application software platform) is capable of producing robust static web pages to put in the webshare folders.  Links between pages would have to be managed manually, but the effort to do so is no greater than the effort to do so in Manila -- maybe less.  (3) I'm functionally fluent in ASP (including ADSI interface access to Active Directory), HTML, CSS and SQL, and somewhat less fluent in PHP.  I certainly don't consider myself to be anything close to "expert." (4) We have Sharepoint installed, and are considering that as part of the local mix.

Having said all that, here's the vision and the problem:

Professional pages should be created and maintained in Word 2007, and stored/served from a webshare subfolder in the individual's home directory.  Security permissions for editing vs. reading should be controlled by NTFS/Active Directory.   A Microsoft SQL 2000 Desktop instance has been created on the IIS server to support the website, but no tables have been created yet.

Somewhere somehow the professional pages need to be encapsulated in a template wrapper (the template is already fully developed using CSS floated boxes, and can be seen at http://services.bbps.org/theme3/index.asp).   The Word-created HTML pages should appear in the large white section to the right of the navigation menu.

The problem so far has been that Word-created HTML pages include their own styles, fonts, and tags.  If the file is simply imported into it's proper sequence in the template, you have nested <HTML>, <META>, <HEAD>, <STYLE> and <BODY> tags that are consequently misinterpreted.  I'm in the process of experimenting with framesets, but understand that frames have been deprecated.  If I store the Word-created pages as BLOBs in the SQL database, it's still not a matter of just adding the template segments around them -- the nested tags still exist.  Of course, Manila accomplished this by requiring use of their own HTML editor that couldn't understand the complex markup in Word documents.  And storing them in SQL implies a two-step update process: (1) open the document in Word and make the change, then (2) upload it to SQL again.  Ideally, it should be enough to just open it in Word, make the changes, and save it again, just like any other document. 

So what I really need to do is display NESTED web pages (a web page inside another web page), where both the inner and outer pages are fully independent and standards-compliant.

So... any ideas?

Tags: CSSembedHTMLprojectsVB.NET




CSS Lesson 1 of 4: What’s CSS and Why Do We Need It?

Cascading Style Sheets (CSS) is a powerful way to add styling and to control a web site’s appearance.

CSS was created to work along side HTML, however it is a different language compared to HTML. You can use CSS to control everything from the color of your text to how far apart elements are spaced on your page. CSS will also let you change the color and background of an element as well as adding borders to an element. It will even allow you to do more advanced stuff like popup windows. One of the real benefits of CSS is it allows web designers to separate the content from the presentation and have all of a site’s presentational information in one location.

The "cascading" in "cascading style sheets" is basically the order of precedence that the browser uses to apply style rules. If there are any conflicting declarations, the cascade is the process that sorts it all out and determines which rule will finally win. In other words, the style rule with the highest precedence is the one that is used. One of the simplest forms of precedence is that the style that has been declared last on the page is the one that will be applied – that is, if all other things are equal.

Now that I have given you a brief synopsis of what CSS is, let’s talk about why we need it. In the beginning, well before CSS at least, HTML was used to control the presentational aspects of a page. With web sites becoming increasingly complex, a majority of the code merely determined the appearance of a web site. While this did not create any problems for the end user, it made web site maintenance especially difficult and time-consuming. For example, to change the color of your links, you would need to go to each and every link and change it manually.

So in 1995, the World Wide Web Consortium (W3C) began working on a solution. By 1996, the W3C came up with, you guessed it, CSS. Using CSS to move the presentational information out of the HTML document not only makes web sites easier to update and maintain, but it also has several other benefits, such as cleaning up the code, making the web sites easier to be indexed by search engines, and making websites more compatible with screen readers. CSS also gives you more options and can make a much richer looking web page than HTML ever could.

Resources for CSS Class
Rock Paper Scissors Demo
RockPaperScissors.zip
lesson4.zip
Pixie (Windows Only)

Notes for Mac Users: If you are having trouble using "TextEdit" to view the code of the HTML files, open up the preferences of TextEdit and under "Open and Save" make sure "Ignore rich text commands in HTML files" is checked.

Instead of using Pixie to grab the hex value of a color you can use the Digital Color Meter in the Utilities folder in Applications.  Select "RGB As Hex Value, 8-bit" from the drop down list in Digital Color Meter and when you are over a color you like do a shift-comand-c to copy the value to the clipboard. For some reason when you paste the hex value it has quotation marks around it so don't forget to remove them.  

Some Great Websites to Learn More About CSS
The W3C CSS Home Page
W3Schools CSS Tutorial
Zen Garden



Tags: CSSTECHS




CSS Lesson 2 of 4: CSS Placement

CSS can be placed in three different places in your web site. First, it can be placed in-line within an individual element. Second, it can be inserted at the top of a single web site page. Lastly, it can be in an external CSS file.

In-Line Style
The easiest way, although probably not the most recommended way, to add a CSS style to an element is to put it directly in the tag. You can add an in-line style to any HTML tag as long as it is within the BODY tags of your page. For example, if you wanted to make all of the text within a div tag red, you would do the following:

<div style="color:Red;">Hello there.</div>

You just want to make sure that you do not forget your semi-colons and quotation marks. One thing to note here is that in-line style declarations will get the highest precedence in the cascade and will be applied over any other conflicting rules. Like I said, this is not considered the best way to set a CSS style to a tag. It is little better than the old way of just using basic HTML. Setting all of your styles this way would make your code harder to read and even harder to maintain. But there are times when it can be very handy, especially when creating a web site and you are troubleshooting a particular CSS error or when you want to apply a style quickly so you can see how it looks.

CSS for One Page
If you just want your CSS rules to affect one web page, you can put your CSS all in one location in the HEAD of your document. All you need to do is use the style tag in the head of your web page. The following example tells the browser to show any text within an element that has the class "blue-text" with a blue color and to show any text within an element that has the class "red-text" with a red color.

<head>
    <title>my awesome webpage</title>
    <style type="text/css">
         .blue-text { color:Blue; }
        .red-text { color:Red; }
    </style>
</head>

Site-Wide Style Sheets
The third and most common way to add CSS to your web page is to use an external file with all your CSS rules in it. There is nothing really all that special about the CSS file itself. It is just a plain text file with an extension of .css. You just need to make sure you remember to tell your web page where the CSS file is by adding a link tag in the HEAD of your web page. In your link tag, just make sure you include rel="stylesheet". By the way, "rel" stands for relation. Make sure to set the type to text/css. This is very important because it tells the browser how to import the data.

 <link href="/default.css" rel="stylesheet" type="text/css" />
Tags: CSSTECHS




CSS Lesson 3 of 4: CSS Structure: Part 1


CSS Lesson 3 of 4: CSS Structure: Part 2

A CSS statement or “rule” has two main parts:  the selector and the declaration.  Let's take a look at the selector first.

Element Selectors
There are several different types of selectors.  The most basic type of selector is the HTML element itself.  This allows you to easily apply a set of rules to a certain element type all at once.  For example, if you wanted to make all of the text within a H1 blue, you would do the following:

h1 { color:Blue; }

You can even use two or more elements at the same time as the selector.  You just need to separate them with a comma.  There is really no limit on how many selectors you can have.

h1, h2, h3 { color:Blue; }

Class Selectors
Another way to apply styles to elements is to use the class selector.  Instead of having an element name as a selector, you use a class name preceded by a period.  The period must always be used before the class name because that is what marks it as a class selector.  Using a class selector is probably the most common and beneficial way to add styles to a web site as it enables you to be more selective on which elements the style is applied to.  To use a class with a certain element, simply set its class attribute to the name of the class.  In fact, you can even set several classes to a single element.  Just make sure you have a space between the different class names.  And don't forget that CSS class names are case sensitive.

<html>
    <head>
        <style type="text/css">
            .blue-text { color:Blue; }
        </style>
    </head>
    <body>
        <div class="blue-text">
            This text is blue.
         </div>
     </body>
</html>

ID Selectors
ID Selectors are used a lot like the class selectors but there are a few differences.  Instead of using a period like with the class selectors, you need to use a pound (#) sign, or as I like to call it, the little itty-bitty tic-tac-toe sign.  To use an ID selector, you use the ID attribute of the element.  Unlike classes, IDs can only be used once per page since IDs have to be unique for that HTML page.  Also, don’t forget that just like classes, ID selectors are also case sensitive.

<html>
    <head>
        <style type="text/css">
            #blue-div { color:Blue; }
        </style>
    </head>
    <body>
        <div id="blue-div">
            This text is blue.
         </div>
     </body>
</html>

The Declaration
The correct syntax for a declaration is a property followed by a colon and then a value followed by a semicolon.

h1 { color:Blue; }

In this example "h1" is the selector, "color" is the property, and "Blue" is the value.

One thing to note is that syntax is very important when writing out your declarations.  If you make a mistake or have an invalid declaration or keyword, then the whole rule will just be ignored.

Just like you can group selectors together to make a single rule, you can also group declarations together into a single rule.

h1 { color:Blue; font-family: Arial, Helvetica, sans-serif; font-size: 13px; }

This is definitely the preferred way of defining multiple styles for a single selector.  Just remember to put a semicolon after each declaration.  While it might be valid CSS to leave a semicolon after your last declaration, it is generally not considered good practice and I wouldn’t recommend it.
Tags: CSSTECHS



In this lesson we will write a simple 2 column layout using CSS.

Here is the source code for the demo: lesson4.zip
Here is a link to the color picker program (Windows only): Pixie

Mac users: instead of using Pixie to grab the hex value of a color you can use the Digital Color Meter in the Utilities folder in Applications. Start it up and select "RGB As Hex Value, 8-bit" from the drop down list. Then when you are over a color you like do a shift-comand-c to copy the value to the clipboard. For some reason when you paste the value it has quotation marks around them so don't forget to remove them.


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 1


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 2


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 3


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 4


CSS Lesson 4 of 4: Let's Write Some CSS Already!: Part 5
Tags: CSSTECHS



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