Unfortunately, I haven't updated this website in a very long time. I have since developed 20+ Wordpress websites that are not included in this site's portfolio. Please contact me for an updated portfolio

Posts Tagged ‘css’

Learning xHTML and CSS – day 6 of 30

Learning xHTML and CSS – day 6 of 30

It’s been 6 days and already we have created a simple xHTML document. We learned some valuable and fundamental xHTML tags and begun our journey into the world of website design and style using CSS definitions. Today will be the last day that we focus on CSS and leave the xHTML alone. Tomorrow, we’ll modify some of the xHTML tags, add a few more tags to give us more room for playing around/styling,  and start working towards the final structure of our website.

To recap:

This is where we currently stand with xHTML markup:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

And this is where we currently stand with CSS style definitions:

body {
 background-color: black;
 color: white;
}

p {
 background-color: gray;
 font-weight: bold;
 font-style: italic;
}

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
 border: solid 1px red;
 padding: 10px;
 margin-bottom: 10px;
}

What’s next?

The text-align property

CSS allows us to choose a text-alignment just like Word does. If you call, Word has four text alignment options: left aligned, centered, right aligned, and justified. Well, CSS has those exact same features with these definitions:

text-align: right;
text-align: left;
text-align: justify;
text-align: center;

So now, given those properties, let’s right align the paragraphs. Add this to your ‘p’ selector CSS definitions:

text-align: right;

And the result is shown in the picture on the right.

For those of you who want to make websites in languages reading Right to Left, you’ll find yourself in a serious situation if you don’t declare a right to left reading direction in CSS. Here’s how I recommend doing that. I won’t take a screenshot of what this looks like because I won’t add it myself, but just know that in case you want to write a website in Hebrew, Arabic, or any other right-to-left language, you should add this to your ‘body’ selector definitions:

direction: rtl;

So that your body becomes:

body {
 background-color: black;
 color: white;
 direction: rtl;
}

But, like I said, I’m going to remove it from my ‘body’ definitions since we’re writing in English.

The last thing I’ll introduce today, which may be a little too complicated for this part of the course, is called a pseudo-selector. What’s a pseudo-selector? It’s a selector that modifies a primary selector. Enough with this mumbo jumbo, how does it look like? Like this:

selector:pseudo-selector { styles go here }

I’ll introduce one pseudo-selector in this lesson and then we’ll forget about it until later in the course. The pseudo selector in question is called the first-child pseudo selector. If we declare this:

p:first-child {
  color: blue;
}

The first paragraph (‘p’ tag) will have a color blue, while the rest of the paragraphs will be in the previously determined color (white in our case). So let’s actually add that to our CSS file and see what we get (shown right).

Well, we got nothing different then what we had before. And why do you suppose that is?

It’s simple, the :first-child selector targets the first-child of the targeted tag. In other words, the first-child new definition we have added to our CSS only targets the first paragraph that goes directly beneath the <body> tag. If we, for example, now add a paragraph tag directly beneath (also known as first-child) the <body> tag, we’ll get this:

Thus, I’ve added a paragraph (‘p’) tag to the xHTML, and so our HTML is currently the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<p>This is a direct descendent paragraph of the body tag.
It can also be called the first-child paragraph.</p>
<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

And our CSS is the following:

body {
 background-color: black;
 color: white;
}

p {
 background-color: gray;
 font-weight: bold;
 font-style: italic;
 text-align: right;
}

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
 border: solid 1px red;
 padding: 10px;
 margin-bottom: 10px;
}

p:first-child {
 color: blue;
}

And the resulting outcome of this is the picture shown on the right. Notice how the first paragraph, which is the first-child of the <body> tag, is blue-colored, while the rest of the paragraphs are white. Let’s now delete that first-paragraph from the xHTML and delete the first-child CSS style definition so that we go back to a clean beginning for tomorrow.

Summary

We learned some text-align CSS definitions today as well as introduced the concept of a pseudo-selector. I didn’t originally intend to change the markup code, but things had to be done…

Be sure to subscribe to the RSS feed so you can get the new post by email. Also, feel free to contact me with any questions or use my contact form to send me any private comments or questions.

Thanks for reading!

Learning xHTML and CSS – day 5 of 30

Learning xHTML and CSS – day 5 of 30

Shown on the left is the end point of yesterday’s lesson. Again, we didn’t touch any of the xHTML markup, but rather used external CSS stylesheets to add style and pizzazz to our site. Let’s continue on this same road, add a few more style properties, and see what we can else we can do with the power of CSS.

The XHTML code until now:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

The CSS code until now

body {
 background-color: black;
 color: white;
}

p {
 background-color: gray;
 font-weight: bold;
 font-style: italic;
}

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
}

Okay. This is where we’re currently situated. Now let’s add a few more styles.

The border property

The border property is used to give xHTML tags (or elements) a…well…border. Couldn’t have guessed that could you! Let’s make our h1 tag have a solid border of 1 px in width with a red color:

Thus, we add this to our CSS file:

border: solid 1px red;

So our h1 style definitions look as follows:

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
 border: solid 1px red;
}

The border definition gives the h1 tag a border. What type of border? A solid line (other types are dashed, dotted, etc…). How wide is the border? 1 pixel wide. And finally, what color is it? Red. The picture on the right shows the outcome of this definition. See that red border around the h1 tag?

Do you also see how the h1 tag is feeling a little smooshed within that border? We can tell the browser to give it a little room with CSS using the padding property.

The padding property

Let’s add this to our h1 tag definitions:

padding: 10px;

Combining our styles to:

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
 border: solid 1px red;
 padding: 10px;
}

Padding tells the browser to give the h1 tag a little room to breathe. How much room? 10 px. Where? In all four of the surrounding sides. You can also control the specific padding to each side, as follows:

padding-top: 10px;
padding-bottom: 10px;
padding-right:20px;
padding-left: 20px;

But for now, let’s stick to the same padding in all four sides. This transforms our site to the picture on the right.

The last property we’d look at today is the CSS margin property. Do you see how the red border around the h1 tag is touching the paragraph ‘p’ tag. Let’s change that. Make things a little cleaner. Make the paragraphs move down a little.

This property is called the margin property. Similar to the padding property, margin can be specified as:

margin-top: [number in px]px;
margin-bottom: [#]px;
margin-left: 10px;
margin-right:20px;

So let’s give the h1 tag a bottom margin so it’ll push down the paragraphs a bit. Add this to our h1 definitions:

margin-bottom: 10px;

That should do it. The picture on the right shows the outcome. Now isn’t that cleaner?

Summary

None of the xHTML code was modified today. All we touched on was the CSS. We added a few more styles to make our site look a little different. I know it’s still ugly, these yet simple examples always are. However, as we advance in the course, things will get a better look, just wait and see. Always remember the goal of the course. After 30 days, you’ll be able to write a website, from scratch, that looks and stands strong next to other sites. And you got this education for how much? Oh, that’s right. Free!

Well, that’s all for now, see you tomorrow!

Learning xHTML and CSS – day 4 of 30

Learning xHTML and CSS – day 4 of 30: More on CSS properties

The picture on the left summarizes where we left off last time. We introduced the use of Cascading Style Sheets (CSS) to style our xHTML markup code (our website) without touching the xHTML code at all. Today’s lesson will build on yesterday’s lesson, in that we won’t touch the xHTML code at all, but only the CSS to further add some styles to the text.

The xHTML markup

Just in case you forgot or lost it, here is a reminder of the xHTML markup code that we have written and will be constantly repeated throughout this tutorial series:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
<link href="reset.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

The CSS

And this is what we have written for CSS thus far:

body {
 background-color: black;
 color: white;
}

p {
 background-color: gray;
}

h1 {
 background-color: #c3c3c3;
 color: black;
}

Now, let’s not touch the xHTML code, but only touch the CSS code. Ready? Cuz I’m going to throw some new CSS properties at ya!

The font-size property

Let’s say we wanted to have a different font-size? So, let’s think of Microsoft Word for a second. The standard Office 2003 font-size is 12 (Times New Roman), and Office 2007 is 11 (Calibri). Did you ever know that those numbers actually refer to the height of the text in pixels? Let’s use that logic for our font-size CSS property.

Let’s change the font-size of our heading tag to 20 pixels

Add this to your h1 definitions:

font-size: 20px;

Thus, our h1 definitions now become:

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
}

The picture on the right shows what the new outcome of increasing the font-size of our heading. See how the heading (h1 tag) is now 20 pixels? So that’s the font-size property.

The font-weight property

You can also make text bold. The CSS property to make text bold is called font-weight. Let’s make out paragraph text bold. Add this to our ‘p’ selector:

font-weight: bold;

Thus, our combined p selector style definitions are:

p {
 background-color: gray;
 font-weight: bold;
}

And the picture on the right shows the result of this new definition.

The text-decoration and font-style properties

Lastly, (I told you I’ll make today’s lesson shorter…much shorter), you can also make text underlined and italic.

Let’s make the heading tag (h1) underlined, while make the paragraph italic. The way to do this is by using the text-decoration and font-style properties as follows:

text-decoration: underline;
font-style: italic;

See if you know where to place each definition to make the heading (h1) text underlined, and make the paragraph text italic.

If you got it right, this is what your final style sheet should look like:

body {
 background-color: black;
 color: white;
}

p {
 background-color: gray;
 font-weight: bold;
 font-style: italic;
}

h1 {
 background-color: #c3c3c3;
 color: black;
 font-size: 20px;
 text-decoration: underline;
}

And finally, our website looks like this (shown right).

Summary

Today’s lesson was short. We concentrated on CSS. We didn’t touch the xHTML markup. All we did was add a few styles to our currently content-based site. We introduced a few more CSS properties and the result is shown above. Hope you learned a little more!

Thanks and stay tuned for exciting coding!

Learning xHTML and CSS – day 3 of 30

My first website image, lesson 1Learning xHTML and CSS – day 3 of 30

Just a recap, the picture on the left is where we left off yesterday. We built a site with pure xHTML markup code. The site consisted of the necessary conditions such as DOCTYPE, html tag, head tag, and body tag. Additionally, we introduced the concept of headings, such as the h1 tag. And finally, we wrote two paragraphs. Today, we’ll use this template and style it with basic CSS. Today’s lesson will be a little shorter due to the fact that I’ve been extremely busy today.

So, here’s the xHTML markup code for where we left off:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

Now, let’s introduce the concept of CSS, its properties, characteristics, etc.

What is CSS?

If you haven’t read my previous posts, CSS is an acronym for Cascading Style Sheets. In short, CSS is a language of it’s own. However, don’t be afraid, it’s extremely self-explanatory and is atypical to all other programming languages. No if, else, while, for loops in this one! The sole purpose of a CSS file is to provide styling to raw xHTML data. The CSS file has complete control over the style and look of the page. Without the CSS file, modern tableless websites will look horrendous. The advantage of table-based websites is that they have basic styling due to the structure of the table. Don’t be fooled though, the potential styles you can obtain from using CSS go far and beyond the basic and structured table-based sites. Enough with the babbling, let’s see it in action.

The CSS reset file

Many websites (including mine) use a CSS reset file. The reasoning behind this is simple. Browsers already have defined styles for certain xHTML markup code. This is why the heading in our first site (h1 tag) is large and bold, and the paragraphs are separated by a line-break. The problem is different browsers have different default styles for these, and it gets extremely annoying and difficult to override all of the default styles. Therefore, a CSS reset file resets all default styles. The following is how to make the CSS reset file. Make a file called ‘reset.css’, open it with your favorite text-editor, and place the following code in there:

/* Global reset */
*, html, body, div, dl, dt, dd, ul, ol, li, h1, h2,
h3, h4, h5, h6, pre, form, label, fieldset, input,
p, blockquote, th, td { margin:0; padding:0 }
table { border-collapse:collapse; border-spacing:0 }
fieldset, img { border:0 }
address, caption, cite, code, dfn, em, strong, th,
var { font-style:normal; font-weight:normal }
ol, ul, li { list-style:none }
caption, th { text-align:left }
h1, h2, h3, h4, h5, h6 { font-size:100%;
font-weight:normal }
q:before, q:after { content:''}

/* Global reset-RESET */
/* The below restores some sensible defaults */
strong { font-weight: bold }
em { font-style: italic }
a img { border:none } /* Gets rid of IE's blue borders */

I should mention that the above CSS reset code is largely based off the free CSS reset file provided by Yahoo! Anyway, let’s now link the CSS file to the xHTML file that we created, thereby making the above CSS code effective on the xHTML data. Here’s how we link the file:

<link href="reset.css" rel="stylesheet" type="text/css" />

This goes in the <head> tag, so overall, our new code becomes the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
<link href="reset.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

And as a result, this is what happens to the same site as before, except with a reset file applied to it (picture on the right).

As you can see, everything looks the same! There are no spaces between lines, nothing bolded or emphasized, none of that. The CSS reset file simply resets everything to normal, equal in all way, shape, and form.

The styles CSS file

Now we’ll make another CSS file and call it ‘styles.css’. This file will contain the CSS code that will style our page. So let’s do that now, make another file, call it styles.css, and open it with your favorite text-editor.

Now that you and I have made that file, let’s link it to our site with the following code (identical to the way we linked the reset file)

<link href="styles.css" rel="stylesheet" type="text/css" />

And make sure the above line is placed below the line that links the reset.css file! Now let’s add some code to the styles.css file and add a little style to our page!

First, as you saw in the picture and as you saw if you opened the page with the linked reset file, the background of the page is white while the text is black. Let’s change that. Let’s give it a black background and give the text a white color. This is how we do it with css (put this in your CSS file):

body {
  background-color: black;
  color: white;
}

See! That wasn’t all that bad. I told you CSS was self-explanatory. Let’s just analyze that a little before we can continue.

The CSS syntax

All CSS syntax starts with a selector. What’s a selector? In the example above, the selector was ‘body’. This means that the styles that come in between the { and the } are applied to the body of the page. If you recall from the previous post, all of the site’s content is placed under the body tag. Therefore, the ‘body’ CSS  selector is rather global and is typically used to set background color, font color, font size, etc. Lastly, after every style is defined, a semicolon ‘ ; ‘ is placed to entitle the end of a style definition.

So, once you have your selector, you define your styles. As you could’ve probably guessed, the background-color style defines the background color of the page, while the color style defines the color of the text on the site, and always remember, these styles only affect the body selector. Therefore, in this case, the background-color sets the background of the body. Furthermore, instead of writing black for background-color, you can write the six-digit HEX code of a specific color. For example, for black it would be #000000. You can use Photoshop or other image-analysis software to obtain HEX digits for a certain color. Shown on the right is what our new page looks like with these newly applied styles!

Now, let’s apply some background color to only the paragraph tags. The way to do this with CSS is the following:

p {
  background-color: gray;
}

In order to set a background color for the paragraphs, we need to use the background-color style definition and set it on the paragraph selector. What’s the paragraph selector? Well, as you see above, it’s simply just p. Shown on the right is the result of our new site.

As you can see, the paragraph tags have  a gray background color. Remember that the first line “My first website!” is not a paragraph tag, but rather a heading tag. So, the p selector will not affect it. Let’s give that heading a background color as well and a different color text, this time of a lighter gray shade using a six digit HEX number. The selector for the heading tag is simply the type of heading that was used. So, in this case, since the heading is a <h1> tag, we’ll use the h1 selector. Let’s add the following to our style definitions:

h1 {
  background-color: #c3c3c3;
  color: black;
}

As you can see, we used the h1 selector, gave the h1 tag a background color of a lighter gray shade color, and we gave its text a black color. The picture on the right shows the results.

Summary

Today we learned about CSS. It’s important that you realize that we didn’t TOUCH the xHTML markup code. All of these styles were made solely by external CSS stylesheets. The only thing we did to the xHTML markup code was to link the CSS files so they take action on the markup code. This is only the beginning of the powerful features that CSS can do. Stay tuned for more exciting stuff!

That’s all for now! Thanks for reading and see you tomorrow!

Learning xHTML and CSS – day 2 of 30

Basic HTML fundamentalsLearning xHTML and CSS, a 30 day course, for FREE. This is Day 2 of 30

Last time we left off with a need to introduce the CSS reset file as well as the 5 basic HTML markup codes. I’ve made a small change in today’s lesson. Instead of introducing the CSS reset file, I’ll introduce some necessary HTML code that must be present in order for the site to work, as well as some basic fundamental HTML markup code. By the end of today we’ll put content on our first page. We’ll also start to build the structure that will be repeatedly used in the upcoming lessons.

Absolutely necessary xHTML markup code for the site to properly render

DOCTYPE

Every website has a DOCTYPE. What’s a DOCTYPE, well, it’s a type of form that the server uses to render (think of rendering as “understanding”) your site. Basically, there are several types of DOCTYPE, and each type tells the server a different way to understand your code. That’s as much as we’ll go into DOCTYPE. For now, all you need to do is just copy/paste the following line(s) of code into your text editor (as explained in the first lesson).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Above is the DOCTYPE that I always use. I don’t go much into it, I just copy/paste at the top of each site I build.

HTML tag

Every HTML document starts with <html>. However, for xHTML, an additional fragment is needed. I will not go into it, as all you’ll need to do is simply copy/paste this right below DOCTYPE.

<html xmlns="http://www.w3.org/1999/xhtml">

Now that we have our DOCTYPE all set and the HTML tag all set, we’re ready to write the content of the site.

Fundamental xHTML tags

Note: it should be properly stated that all xHTML tags (with exception to DOCTYPE) must be in lowercase letters.

head tag

The head tag is simply:

<head>
</head>

What goes inside the head tag? Well, many things. Inside the head tag is where we link external stylesheets or write the styling mechanisms to properly style our website. Also, if your website is in a language that requires UTF-8 encoding (such as Hebrew, Arabic, and many many other languages), you place a <meta> tag inside the head to indicate a different type of encoding. Anyway, let’s not worry about that for now.

What I wanted to cover is the document title, which also goes inside the head tag. So if we want to give our document a title of “My first website”, this is how we’d do it. First, let’s write the appropriate title tag:

<title>My first website</title>

Note: remember to close all non-self ending tags. Now that we’ve written the <title> tag, we need to place it inside the head tag, as follows:

<head>
<title>My first website</title>
</head>

So, let’s just recap and put the following inside our text editor. Remember to close all tags, meaning the html tag as well. The DOCTYPE does not need to be closed. Let’s copy/paste the following into index.html (edited with a text-editor such as NotePad or Notepad++), save, and open it with your browser.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
</head>

</html>

Opening index.html gives us an empty page with a white background and a title of “My first website”. Awesome!

Let’s put content into the page

The body tag

After the <head> tag comes the <body> tag. Essentially everything goes inside the <body> tag. The body tag looks like this:

<body>
Everything goes inside here
</body>

Here are two examples of content tags that can go inside the <body> tag:

The headline tag: h1

<h1>This is my first website!</h1>

And the paragraph tag: p

<p>This is a paragraph</p>

Now let’s put it all together, save, and open it in our default browser. Copy/paste this into your text editor:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>My first website</title>
</head>

<body>

<h1>My first website!</h1>

<p>
Hello World! This is a paragraph!
</p>

<p>
And this is another paragraph!
</p>

</body>
</html>

What you’ll end up seeing is something like the picture on the right (with variations on browser type)My first website image, lesson 1

Congratulations! We wrote our very own [basic] website with some content in it.

The next lesson…

The next lesson will stick to the above created code and use CSS to style it in different ways. Again, we’re starting with basic concepts, properties, and characteristics. We’ll see how things take us from there.

That’s all for now…check back tomorrow!

Learning xHTML and CSS – day 1 of 30

Back to BasicsDay 1 of 30 – The basics

The first lesson of this course won’t be code-heavy, but rather more informational and theoretical. Before we can delve straight into the heavy code, we need to cover the basics. One last thing before we begin this journey. Do note that I am an xHTML W3C standards compliant modern coder, meaning I prefer the use of table-less designs which have been proved (by many) to be far superior to table-based design. While we’ll cover the use of tables and their respective markup code, we will concentrate and focus on DIV-based (aka modernized style) designs.

The basics

Just as you put on a nice shirt before you go to work [see picture on the left], you should also know that in HTML and CSS and every programming language, what has a start, must also have an end. Okay, the whole shirt thing was by far the worst analogy (if at all an analogy) I’ve ever made. Don’t worry about it, it’ll get better!

The beginning and the end

In html, every beginning of code starts with a ” < ” and ends with a ” > “. Furthermore, xHTML possesses two types of ending: self-ending, and not-self-ending.

A self ending code is one that ends with a ” / ” followed by a ” > “. The image code, for example, is self-ending (the ellipses [aka three dots "..."] represent overlapping code. If you are to copy paste this, make sure to remove the ellipses and bring the string to one straight line):

<img src="images/myimg.jpg" alt="my image" ...
title="my awesome image" width="10" height="10" />

Let’s have a look at the image code and disregard the terms for now. As we discussed before, it starts with a ” < “, then comes the HTML command, in this case, ” img “, which is short for image. This tells the browser that we are inserting an image here. Whenever anything is inserted or linked or referred to within a document, you’ll frequently see the ” src ” code, which is short for source. This tells the browser to put an image that is located in the folder named “images” with the name of “myimg.jpg”. The ” alt ” tag is used for browsers that do not view the images for some odd reason (perhaps not enough bandwidth to download image, perhaps images blocked, etc. etc.), and instead of displaying the image the browser will display the alt (short for alternate) text. The commands the follow are self-explanatory. Do note that whenever height and width are used within an xHTML markup code, they are referring to pixels. In this case, this picture is 10 px by 10 px.

The reason I chose to start this course with the image markup is because it shows a great example of self-ending markup code. However, most commonly used xHTML markup code is not self ending. Take for example the <body> tag:

<body>
</body>

The markup code for the ” body ” tag starts with <body> and ends with </body>. This is an example of non-self-ending code. Another example of this is the division (DIV) tag:

<div>
</div>

And so on…

We’ll cover more xHTML commands and markup code later in the course, but for now, make sure you understand the difference between self-ending and not self-ending commands. Also make sure you fully comprehend the fact that every statement in any programming language has a start and an end. Whether it’s with ” < ” and ” > “, or with brackets, or with curly brackets, or parentheses, what-have-you, it must end somehow.

The next lesson

The next lesson will introduce the CSS reset file, explain why it’s useful, and explain the first 5 useful HTML markup code necessary to begin building your own website. So stay tuned!

Learning xHTML and CSS

Hi all,

This post will be quick and short. I’ve decided to type a small/short post every day (or every other day) that shows small snippets of HTML and CSS code. I will show and describe most of the HTML and CSS properties, and I will discuss object oriented CSS and regular CSS.

Sooo latch onnn, because it’s about to get bumpy! I will teach you HTML and CSS from scratch NOT the way I learned it (because my way of learning was the hard and redundant way), but through the proper way of learning xHTML and CSS markup code.

What to expect at the end of this 30-day HTML and CSS tour?

At the end of this 30-day HTML and CSS tour, you will be able to have a solid grasp of xHTML and CSS, and you will be able to self-program (aka NOT use software such as Adobe Dreamweaver of MS Front-page) to write and program your own website.

If you’re ready to learn and want to write your own website rather than pay someone (like me) to do it for you, check back daily and remember to practice the code that was discussed!

Your first assignment: What do xHTML and CSS stand for?

One last thing

Throughout this course, I will present a lot of code (both xHTML and CSS code). The question is, where do you put this code so that you can double click a file and have it open in your browser with the content that you put inside the code, right?

Basically, in order to open a file in your browser, it should have a ‘.html’ extension (other extensions are allowed as well, such as .htm, .asp, .php, and others, but for now, stick to .html). How do you create a html file?

Two ways:

Option 1

1) Make a regular text file and call it whatever you want. Let’s call it index. This will create a file called index with extension ‘.txt’, hence index.txt.

2) Double click it and have it open in Notepad, then input all of the code/content that you want in there

3) Save and close. Rename the file index.html. Double click it, and it should open in your default browser (whatever it may be).

Option 2

1) Similar to option 1, make a new text file. Remove the default name and .txt extension, and name it index.html

2) Right click it and select Open With -> Notepad, or if you have a text editor such as Notepad++ (highly recommended), Right click it and select Edit with Notepad++

Leave a comment or email me [contact@engineercreativity.com] or contact me [http://engineercreativity.com/#contact] with any questions.

That’s all for now! Check back later today or tomorrow!

Simple client-side (Javascript) validation

A simple javascript client-side validation

Have you ever seen those forms (such as the one on the left) that ask you to type a password twice, once to create it, and once to confirm it? Well, there are many security and stability reasons behind that which will not be discussed here, but I wanted to focus more on the validation / confirming aspect of it.

The validation

You have to think about the easiest and simplest user interface. As you know me, I like to use the jQuery Javascript library. In this post, I will show you how to write a simple jQuery script that will check/verify that the two passwords do in fact match, and in the case that they don’t match, and error message will pop up.

The script

Here’s what you need to think about.

1) When the user clicks the first password field, do what?

2) When the user clicks the second password field, do what?

3) When the user clicks away (blurs, if you don’t know what blur is, refer back to the previous post) from the second password field, do what?

4) When the user clicks Submit (or in the picture about, “Register Now!”), do what?

So those are the four things you need to think about, now let’s get on with it.

1) What to do when the user clicks on the first password field

Well, in this specific post which refers to a very simple validation code, I’m going to say nothing. However, many scripts try to ease the user’s experience with the form, so when the first password field is pressed, a message on the right pops up saying “At least 5 characters, no “/” or other such things”…Rings a bell?

Anyway, refer to the previous post if you’re confused, but basically here’s how we’ll do that:

$('#pass1')
  .focus()
  .append('<span id="spanpass1">At least 5 characters, no blah blah</span>')
  .blur()
  .remove('#spanpass1');

Then we can use CSS and absolute positioning to correctly position the span with id spanpass1 such that it is positioned appropriately. Additionally, notice the great chaining that can take place with jQuery (truly awesome!).

2) What to do when the user clicks on the second password field

In this case, I would do nothing. Some choose to show a password strength indicator. But whatever, I’m going to ignore it for now

3) What to do when the user blurs from the second password field

This is important. This is the first part of validation. After we write the code for this, we can practically copy/paste for #4 (submit button click). Here it goes:

$('#pass2')
    .blur(function() {
    var pass1 = $('#pass1').val();
    var pass2 = $('#pass2').val();
  
    //validation part
    if (pass1 = pass2) {
      $('<span id="confirmpass">Passwords match!</span>').appendTo('#pass2');
  } else
      $('<span id="failpass">Passwords do not match!</span>').appendTo('#pass2');
  }
});

Again, use CSS absolute positioning to correctly position the spans. You can also use jquery’s width(), top(), position() functions to dynamically determine the items position, and thus use javascript to position the spans, but that’s another story…

4) Finally, what to do when the submit button is clicked

When the submit button is clicked, you want to create the same two variables (pass1 and pass2) and check for their values. Pretty much, copy/paste item 3, as follows:

$('#submit')
  .click(function() {
    var pass1 = $('#pass1').val();
    var pass2 = $('#pass2').val();

    //validation part
    if (pass1 = pass2) {
       // do nothing
    } else {


      alert('Passwords do not match!');
      return false // disables the submit action

}
});

That’s all folks. Hope it works out. Let me know if there are any errors, since I just wrote this script especially for this post and have not had a chance to test it out. It should work though. See you till the next time!

Textboxes and their common practices

Well, the topic of discussion for today’s blog post is text boxes. There are a wide variety of actions commonly used with text boxes. For example, their radius, their border, their focus event, their hover event, and so forth. In this article, we’ll discuss some of these actions/behaviors.

The hover event

It’s common practice to set a hover state to a textbox. It can range from a subtle change such as a border color, to a largely visible change such as varying border width, color, and background color. So how do we do this hover effect?

Using CSS and modern browsers (not including IE)

#textbox:hover {

/*commands here*/

}

That’s right folks, it’s as easy as that!

Using jQuery

$(‘#textbox’).hover(function() {

//on hover command here

}, function() {

//on off command here

});

Another common practice is to set a focus event

A focus event is probably the most common. What is focus? Well, when you click a textbox to write in it, you’re focusing on the textbox. When you’re clicking anywhere outside of the textbox, you’re blurring from the textbox. Using this, we can assign the following events

Using CSS and modern browsers (not including IE)

#textbox:focus { border-color: red; }

Using jQuery

$(‘#textbox’).focus().css(‘border-color’,'red’);

$(‘#textbox’).blur().css(‘border-color’,'green’);

So, to sum up…

We looked at a few common practices used with text boxes. We discussed the appropriate terms for textboxes, such as hover states, focus states, and blur states. And lastly, we considered both the CSS solution which is supported by modern browsers such as Firefox, Safari, and Chrome, while the jQuery (Javascript) solution is supported by all browsers.

And lastly

To give your textboxes a little more juice, consider giving them a feathered radius (to make them a little more circular). This can be achieved using CSS and modern browsers such as Firefox, Chrome, and Safari, or using CSS and backgrounds which would be supported by all browsers. In either case, do this:

#textbox { border: solid 1px black; -moz-border-radius:10px; -webkit-border-radius: 10px; }

Try it, it does wonders!

An opinion and explanation about Cascading Style Sheets (CSS)

Cascading Style Sheets

To be perfectly honest with you, CSS is one of the simplest languages I have ever dealt with. For starters, it’s completely self explanatory (more on that later). Secondly and perhaps most importantly, it’s doesn’t require the typical programmer’s mindset.

What do I mean by that? Well…first of all, if you’re reading this and you’re an avid CSS coder, I apologize in advance. I myself favor CSS, and I think it’s a great and powerful language to style markup data. But seriously, let’s face it, you don’t see if/else, for/while, end ifs, etc. in CSS.  Perhaps that’s what makes it so easy to learn!

Back when I started to learn website design (three years ago), I found myself starring onto CSS stylesheets and XHTML markup of sooo many websites that I cannot even describe. But that was how I learned. Perhaps it wasn’t the most efficient form of learning, as I didn’t buy a book, take a course, or have someone explain what the hell the differences between “class”, “id”, “#”, and “.” were and which to use when. Remember, during this time, I was also taking classes such as Thermodynamics, Separations, Kinetics and Reactor Design, and many other Engineering classes whose names probably mean squat to the general public. So I didn’t exactly have all the time in the world to dedicate to website design. But I knew I enjoyed it, and that’s probably what drove my passion toward truly and deeply understanding CSS/XHTML, and later on Javascript, WordPress, and some PHP.

CSS is self-explanatory

Like shown in the picture above, CSS is so easy to learn. Before I continue, it’s imperative to mention that the notion of CSS is based on non-tabular websites, i.e., websites that don’t use <table> tags. Instead, websites that are built on <div>, <span>, etc.

What is a DIV? When I first looked at XHTML markup data, all I saw over and over again was DIV this and DIV that. Everything was wrapped in a <div>. I googled “DIV” and only got more confused. So, let’s clear that up. A DIV by definition is a DIVISION block. A div can be nothing, as in not even shown on the website, having a height of 0, width of 0, or it can wrap the entire site. DIVs are used in conjunction with CSS to style the website.

Styling a basic website

Let’s say we want to have a basic website style that includes a box for the header at the top, a box for the main content in the middle, and a box for the footer at the bottom. The markup for that would be very easy:

<HTML header gibberish>
<body>
<div id=”container”>
<div id=”header”>
	<p>This is the header DIV</p>
</div>
<div id=”middle”>
	<p>This is the middle DIV</p>
</div>
<div id=”footer”>
	<p>This is the footer DIV</p>
</div>
</div>
</body>
</html>

A few things I want to discuss about the above code:

1)      Why did I wrap the page with a DIV called container?

2)      What will this page look like without a CSS document attached to it?

3)      Proper XHTML markup

Point 1

I can’t speak for all designers, but I know myself and many many other web developers wrap their entire code in a DIV typically called “container”, “pagewrap”, “outerwrap”, etc. Why? Well, first for convenience. Say you wanted to give your page a top margin of 20 pixels so it doesn’t start right at the top of the browser. You could do this in two ways, the first way would be:


body {
margin-top: 5px;
}

The second way would be:


#container {
margin-top: 5px;
}

Which is better? They both accomplish the same thing, so you can’t say which is better. However, by wrapping your code with a container DIV, you could give it various types of backgrounds, while still having a body background that is separate from the content’s background. Blah, that’s a little confusing. What do I mean by that? Well, say you wanted to have two backgrounds at the top of the page, one of the backgrounds extends the entire width of the browser viewing range, and the second background extends the width of the container DIV (otherwise known as BOX). An example for is background shadows. Before the advent of CSS3 (which is not supported by older browsers such as IE7), shadows were created using repeating background images. To accomplish the shadow effect, the background image was typically placed behind the container DIV, and it was repeated either horizontally (if the container DIV has a fixed height), or vertically (if it had a fixed width ß frequently the case). Either way, wrapping your code with a container DIV is very, very useful.

Point 2

Without CSS, the won’t look different than typing the following:

<p>This is the header DIV</p>
<p>This is the middle DIV</p>
<p>This is the footer DIV</p>

Why? Because the DIVS don’t have any styles applied to them. Therefore, the width they obtain is 100% of the browser’s width, and the height they obtain is 100% of the respective content’s height.

But we can do the following:


#header {
Height: 100px;
Width: 100%;
Background-color: gray;  /* background-color of the DIV */
Color: black;  /* this the font color*/
}
#middle {
Height: 400px;
Width: 100%;
Background-color: #c3c3c3; /* here I use the hex # to color the background of the DIV */
Color: black;
}
#footer {
Height: 100px;
Width; 100%;
Background-color: #cccccc;
Color: black;
}
#container {
background-color: red;  /* think you’ll see any red? Try it out! */
}

Try it out. Put these styling to the test and see what you get. Before I continue, I must mention that a styles reset sheet (commonly referred to as reset.css) is absolutely a MUST for any website. Various browsers apply their own set of predefined styles to DIVs, lists, paragraphs, headers, etc., and you don’t want to deal with that. You want to have 100% control on the styling, and you want all of the styling to be as a result of your coding.

Since this post is a little lengthy, I will continue this post next time (probably in one or two days) and show the finished product of the above code. Also, I will discuss more tips about CSS, and working with CSS properties.

For now, thanks for reading, and I hope you enjoyed it! I’m also thinking of posting up screencast tutorials about javascript, xhtml/css, and wordpress. Would always love to hear your input about it.

Thanks again!

Amit

Reference

Picture taken from Wikipedia under the search-term CSS.