How to use nitrous.io to create a quick and easy web server in less than 5 minutes

Nitrous.io is a cloud service provider that gives you a linux vm running node.js with an I?DE and terminal –  all from your browser.   In less than 5 minutes you can have a NodeJS web server up and running in the cloud.  Here is how:

1.  Sign up for a Free Nitrous.io account.

2.  Create a new box.  Be sure to select the NodeJs stack.

3.  From the terminal type:

mkdir web

cd web

npm install -g express

express

npm install

4.  Now you can start uploading your static content files to the public folder

5.  Start the node server, make sure you are in the web folder

cd /web

node app.js

Now your web site is running.  On the main menu click Preview and then select port 3000.  Now you can browse to your web page.

nitriuos

Why?  Why not use a real IDE?

Nitrous.IO provides a full web app development environment from your browser.  Try running NodeJS on your IPad, Android or Win RT tablet – not an option.  This is powerful platform because we can be anywhere and within minutes can be hacking on a new idea from a mobile device.

HTML & CSS: Lesson 8 – Debugging CSS

If you have spent any time actually trying to build web pages with CSS and HTML then you understand how critical being able to debug your code is.  CSS is an extremely powerful technology that allows you to build engaging web pages but it is also a temperamental  pain in the neck.  Sometimes getting the CSS to do what you want consistently on all of the 3 major browsers will make you want to slap the electricity out of your computer.

So lets look at some tools for debugging your HTML and CSS.  Google Chrome will soon become your new favorite browser.  The developer tool bar is an powerful utility that allows you to be able to inspect the HTML, CSS and JavaScript of any web page.  If you have not already installed Google Chrome, go back to Lesson 1 and follow the instructions for installing it.

The Developer Tool Bar

Fire up Google Chrome.  In the top right hand corner of the screen you should see a wrench.  Click on it and go to the wrench.  Then go to the tools menu and then click on the Developer Tools.

You should see a new panel appear in the browser window.  This window will become your new best friend.

First thing you should notice is the tabs across the top of the developer tools panel.  Elements is the only one we care about right now.  Click on it.  (The other tabs are totally awesome and are invaluable when developing web apps.  But just not for this post.)  The elements tab gives us all of the information about the HTML and CSS.

It gets better.  As you drill into the HTML you will notice that the web page will highlight that area in the browser.  Conversely, if you right click on anything on the page and select “Inspect Element” from the pop menu.  It will find that element in the HTML and highlight it for you.

And if that wasn’t cool enough, the CSS for that element will be displayed on the panel on the right.  Some tag acting weird and not doing what you thought it should be doing?  This panel will give you some clues as to why.

This also gives you a great way to easily study someone else’s work.  Sometimes I‘ll be cruzing the web and see some slick styles.  Right click and inspect element – review the CSS and now I have a new tool in my tool box.

One more nugget – you can edit the page styles from the CSS panel.  Click on a style and you can edit it.  Not sure you like the font color.  No problem.  Find the style for that tag and change it in the editor.

This is a great way to prototype web page design.   Just remember what you changed because the Developer tools will not modify the CSS for you.

The Chrome Developer Tools are fantastic.  And they have many more great features that we will discuss in future blog posts.

HTML & CSS: Lesson 7 – CSS Super Powers

In the last lesson we glossed over a lot of concepts in CSS.  So this lesson we are going to demystify CSS.  In the last lesson we discussed what CSS was and how it interacts with the HTML.  We also saw how it is used to style our page to make it look cool!

The main points that you need to know (see the last lesson if any of this does not sound familiar!) are:

  1. You must include a <link> tag in the HTML so that you can link your HTML document to the style sheet if you choose to use an external style sheet.
  2. CSS lives in .CSS files (aka style sheets)
  3. CSS changes the size, color, position, appearance of HTML tags.
  4. CSS selects the HTML tags by using classes, ids and tag names
  5. An HTML tag may have 1 id and / or many classes

CSS Selectors

Lets review our menu CSS to really understand how CSS is affecting how the HTML tags are rendered by the browser.  Below is the CSS that takes our ugly div and list and turns them into a beautiful menu bar and menu.

#menuBar
{
height: 84px;
width: 100%;
background: url(images/menu-bg.png) repeat-x;
}

#menu
{
list-style-type: none;
text-align: center;
display: inline;
}

#menu li
{
display: inline;
padding: .2em 1em;
background-color: #036;
margin: 15px;
}

#menu li a{
text-decoration: none;
color: #fff;
}

#menu li:hover
{
color: #fff;
background-color: #369;
}

A CSS selector is simply a mechanism to define which HTML tags will be affected by the styles.  Lets look at the #menuBar CSS.  This select says for every tag that has an id=”menuBar” set the height, width and background.

#menuBar
{
height: 84px;
width: 100%;
background: url(images/menu-bg.png) repeat-x;
}

In CSS the # symbol means we are looking at HTML tags that have id=”SomeValue”.  Typically, we are working with a single tag on the page, but this is not a rule.  And HTML document may have multiple tags with the same id.  But this is considered bad practice and strongly discouraged.  This is where the spandex rule kicks in – “Just because you can doesn’t mean you should.”

We can also select HTML tags by class.  For example, look at the following HTML.

<div class=”article”> I am 16px font </div>

<div class=”article red”> I am 16px font and red </div>

<div class=”article ads”> I am 16px font </div>

Suppose we wanted all articles to have a 16 point font.  Then we could use the . (dot) selector to apply the font-size to all tags that have an “article” in the class attribute.

.article {
font-size: 16px;
}

Now suppose we want all tags that have a red class to have a red font color.

.red{
color: red;
}

We can reuse and combine CSS styles to create complex and reusable styles.  This is important.  Don’t miss this.  You can COMBINE styles to create more complex and REUSABLE styles.  Take the time to really digest what a powerful feature this is.  You do not (nor should not) have an individual style for every element on a page.  So if you notice that you are constantly repeating a particular decorator (font-size, color, background, width, height) that you should probably make it an individual style and apply the style to the classes that you need it.

Why do this you may ask? Sounds like a lot of work?  Just a bunch of extra thinking?  Trust me.  It is way better to change the color, width, font, or whatever in one place than to have to hunt the change down in dozens of places and hope that you got them all.  No fun.  Beside other web developers will ridicule your code and talk about your code behind your back.

So we have discussed selecting tags by id and by class.  But you can also select them by name.  Let suppose I want all <h3> tags to be red.

h3{
color: red;
}

Yep.  That simple.

So far you have seen that CSS is extremely useful – but wait there is more!  You can combine these selectors to identify specific tags.  Lets suppose I want all <a> tags in the header div to be red.

<div id=”header”>
<a href=”#”>I am red</a>
<a href=”#”>Me too</a>
</div>
<div id=”mainContent”>
<a href=”#” class=”big”>I am NOT red</a>
<a href=”#” class=”little”>So not red!</a>
</div>

#header a{
color: red;
}

Or if I wanted all tags with a “big” class in the mainContent div to be 24px.

#mainContent .big{
font-size: 24px;
}

Ok so what if I wanted all of the odd links  to be red and all the even links to be blue?  Can CSS do that?  Huh?

#header a:nth-child(odd){
color: red;
}

#header a:nth-child(even){
color: blue;
}

These types of selectors are called pseudo-classes and there are many types.  Some of the more common pseudo-classes are

:hover – the style is activated when the mouse is over the tag.

:focus – the style is activated when the tag has focus

CSS has another super power called inheritance.  Child tags will inherit the decorators of their parent tags.  For example,  lets say I wanted all text on my web page to default to 16px.  I would set the font-size of the <body> tag and then all my children tags inherit that style.  Children tags are any tags that live inside of another tag.  You may have noticed that HTML tags can contain other HTML tags. If a tag contains another tag then that tag then the top level tag is said to be the parent and all of the inner tags are the children.  This a very powerful feature.

Children can override their parents.  So if a parent has a font-size: 16px but the child element needs the font size to be 24px then the child’s style will win.

CSS is very powerful and has many features.  I could not possible discuss all of the decorators or pseudo-classes in this blog post.  But in my next post I will show you how to use the Google Chrome developer tools to steal other CSS super hero’s powers!

HTML & CSS: Lesson 6 – CSS aka Cool Styles for Sites

Ok. CSS Does not really stand for Cool Styles for Sites – but it should.  Cascading Style Sheets just sounds lame.

A style is how something is decorated.  For example, a person may choose to wear a “retro” style of clothing.  It does not change the essence of the person rather it modifies their appearance.  I may not immediately recognize my friend in a 1970 leisure suit but it is still my friend.  CSS styles are the same as fashion styles.  We can change the font, color, size and position of some text on a web page but it does not change the content of the text.  It just changes how it appears.

CSS allows web designers to selectively apply styles to the tags in an HTML document (aka web page).  In CSS we have 3 primary mechanism of deciding how tags get styled.  We can style tags by id, class,  tag name.  (Actually, it is a little more complicated than that but not by much.  We will discuss advanced CSS selectors in a later lesson.  But for now lets focus on the core selectors.)

By id

HTML tags can be given an id or a class(es) or both.  The following <p> tag has been given an id.  The value of an id should be unique with in a document.  So there should be only one tag with the id “importantText”.

<p id=”importantText” >My important text </p>

By class

Classes are different.  Classes allow us to group tags by type.  The following <p> tags have been given a class of “important”. This allows us to define how all important tags should be styled.

<p class=”important” >important message 1</p>

<p class=”important” >important message 2</p>

<p class=”important” >important message 3</p>

Classes can also have multiple groups.  For example I could have a tag that has a class “important” and “critical”.  This tag would be decorated with the styles defined by the important class and the critical class.

<p class=”important critical” >important / urgent message 1</p>

<p class=”important” >important message 2</p>

<p class=”important critical” >important / urgent message 3</p>

By tag name

CSS can also select tags by tag name.  So all <p> will get a style applied.

Creating a style sheet

Lets create your first style sheet and dive right into the code.  In Visual Studio Web Developer 2010 Express open the MyFirstWebSite project.  (See lesson 2 if you don’t have a project to work from.)

Right click on the solution and add a new item.

From the new item dialog select Style Sheet and name it StlyeSheet.css.

In the css file we are going to add a style that decorates all <p> tags with maroon text and large font size.

p {
font-size: large;
color: Maroon;
}

Now save the page and run the project.  Nothing changed?  Huh.  That is because we did not tell the page about our style sheet.  We need to link our style sheet to our web page.  Open the web page (Default.html).  Add the following line someplace inside of the <head> tags.

<link href=”StyleSheet.css” rel=”stylesheet” type=”text/css” />

So the <head> tags should now include a <link> tag.

<head>
<title>My Favorite Stuff</title>
<link href=”StyleSheet.css” rel=”stylesheet” type=”text/css” />
</head>

Now save Default.html and refresh the page.  Notice something different?  The My Favorite Links is now maroon and larger.  Cool.

What else can we do?  How about transforming our favorite links into a menu?

First, we need a way to select the tags that the CSS will effect.  Because this is a menu and our page will only have one menu we will use ids to find the tags. (Incidentally,  adding id attributes is good practice,  Ids  help to improve readability of the html.)

<div id=”menuBar”>
<p>My Favorite Links</p>
<ul id=”menu”>
<li> <a href=”
http://www.bing.com”>Bing.com </a> </li>
<li> <a href=
http://google.com>google.com</a> </li>
<li> <a href=”
http://www.live.com”>live.com</a> </li>
</ul>
</div>

We want our menu bar to be 100% of the page width and the background to be a gradient.  Download the gradient and add it to the project under the images folder (right click the images folder and select “Add Existing Item”).

Next add the following CSS to the stylesheet.css file.  We will cover the more advanced aspects of this CSS in the next lesson.  So don’t panic if you don’t understand everything.

#menuBar
{
height: 84px;
width: 100%;
background: url(images/menu-bg.png) repeat-x;
}

#menu
{
list-style-type: none;
text-align: center;
display: inline;
}

#menu li
{
display: inline;
padding: .2em 1em;
background-color: #036;
margin: 15px;
}

#menu li a{
text-decoration: none;
color: #fff;
}

#menu li:hover
{
color: #fff;
background-color: #369;
}

List style courtesy of http://css.maxdesign.com.au/listamatic/

Now your web site should look something like the following pic.

CSS is very powerful – we are able to dramatically change how our webpage was rendered  by modifying the CSS file.  The CSS Zen Garden Site does a fantastic job of showcasing how amazing CSS styled sites can be.