CSS Tutorial part 3

CSS Links

CSS can be used to add fancy effects to your links, change hover colors and styles, and more.

Since the HTML element for links uses the <a> tag, we can likewise use “a” as the selector in our CSS code:

a {
color:#0000ff;
}

However, we know links can have multiple states. For example, when you highlight your mouse over the link, it can look different. If you’ve visited a link, it can also look different. How can we address these differences?

CSS has built-in “pseudo-classes” which allow us to handle the various states of a link. A pseudo-class looks like this:

a:visited {
color:#0000ff;
}

There are four link states: link, active, visited, and hover. The “link” state is reserved for links the user has not visited. The “active” state is what happens when a link is clicked on. The “visited” state is when a user has already viewed the page the link leads to before. The “hover” state is what happens when you put your mouse over the link but do not click it. We can apply all the states using pseudo-classes like below:

a:link {
color:#0000ff;
}
a:active {
color:#ff0000;
}
a:visited {
color:#000000;
}
a:hover {
color:#0000ff;
text-decoration:underline;
}

By default, links are underlined. If you wish to remove the underline from a link, use this code:

text-decoration: none;

Remember usability though! Users are accustomed to recognizing that links should be underlined.

CSS Borders

Borders can be used for decoration or to separate sections of your page.

Border Size

To set the size of our border, we use the border-width property:

p {
border-width:2px;
}

Don’t try this code just yet! In order to set a border, you must set both the size and the style of the border. We’ll get to that soon enough!

Border Colors

Border colors can be any hexadecimal value or color:

p {
border-color:red;
}

Border Style

There are several different border styles. Let’s first go over how to set our border style:

p {
border-style:dotted;
}

Now we are ready to start playing with the borders. Here is an example of all the different border styles you can use:

Solid

Dotted

Dashed

Double

Groove

Ridge

Inset

Outset

We can also compact our code on to one line only:

p {
border:2px dotted blue;
}

Play around with the borders and see what you like!

CSS Widths and Heights

Widths and heights in CSS are useful to setup the dimensions of our HTML elements.

There are two types of widths and heights: absolute and relative. Absolute dimensions will stay the same regardless of the browser or screen size of the user’s computer. Relative sizes will change depending on the browser and screen size.

Absolute sizes are usually expressed in pixels:

div {
width:100px;
height:200px;
}

Relative dimensions are expressed in percentage terms:

div {
width:100%;
height:50%;
}

Be sure to test out your web page on various screen and browser sizes to make sure everything looks right!

CSS Margins and Padding

“Margins” are how much an element is spaced away from its neighboring elements. “Padding” is how much distance elements or text inside the element with padding are spaced inside the element.

Think of “margins” as on the spacing on the outside; whereas, “padding” is the spacing on the inside.

Padding

Here’s what padding looks like:

Notice how my text has been pushed inside more. This box has a 10 pixel padding.

Now if we used less padding, the text would be pushed “in” less:

Notice how my text has been pushed inside less. This box has a 2 pixel padding.

Let’s take a look at the code to use for padding:

p {
padding-top:10px;
padding-right:20px;
padding-bottom:30px;
padding-left:40px;

We can pad each side of the element by a different number of pixels.

The above code can be compressed to one line:

p {
padding: 10px 20px 30px 40px;
}

In the above code, each side is padded in this order: top, right, bottom, left (clockwise). Each side is separated by spaces.

If we want all sides to use equal padding:

p {
padding: 10px;
}

Margins

The code for margins is very similar to the code for padding:

p {
margin-top:10px;
margin-right:10px;
margin-bottom:10px;
margin-left:10px;
}

Again, we can compact this code as follows:

p {
margin: 10px 20px 30px 40px;
}

As with the padding order, each margin is spaced in this order: top, right, bottom, left (clockwise). Each side is separated by spaces.

Just as with the padding, if we want to space all sides equally, we can do it as follows:

p {
margin: 10px;
}

The above code will space the margins on every side by 10 pixels.

CSS Tutorial part 2

CSS ID Selector

Before we discuss the “ID” selector in CSS, we must first distinguish between a class in CSS and an ID in CSS. Classes and IDs are similar in CSS as both will allow you to style specific elements of your choice. However, classes were designed to be used multiple times throughout a web page. CSS IDs were designed to only be used once in a single web page.

Classes use the period (“.”) sign to denote a class. On the other hand, IDs use the pound (“#”) sign to denote a CSS ID.

Let’s use an example with the <p> tag:

p#redParagraph
{
color:#ff0000;
}

The word following the pound (“#”) sign is the name assigned to your ID. The name of the ID can be anything. In this example, if a <p> tag has the ID “redParagraph” assigned to it, the text in the paragraph would be colored red. To apply an ID to a <p> tag, we use:

<p id="redParagraph">This paragraph will be colored red.</p>

Remember, IDs should only be used once throughout an entire document. If you wish to apply a style more than once, use classes.

CSS guide

Internal and External CSS Stylesheets

Now that we have a basic idea of CSS syntax, we need to add the stylesheets and apply them to our website.

There are two types of style sheets: internal and external. External style sheets are best because they allow you to edit all your CSS in one file.

External Style Sheets

External stylesheets must be added before the </head> HTML tag. It must also be a file in “.css” format. Here’s an example:

<head>
<link rel="stylesheet" type="text/css" href="path/to/your/stylesheet.css" />
</head>

The external stylesheet should not contain any HTML or any other code. Only CSS is allowed. Here’s an example of what’s contained in an external style sheet:

p {color:#ff0000;}
font {color:#000000;}
div {text-align:right;}

Internal Style Sheets

Internal stylesheets are style sheets stored inside the same web page it’s styling.

Just like external stylesheets, internal stylesheets should be placed above the HTML </head> tag.

<head>
<style type="text/css">
<!--
p {color:#ff0000;}
font {color:#000000;}
div {text-align:right;}
-->
</style>
</head>

If a web page is using both an internal and external stylesheet, and both style sheets have definitions for the same element then CSS will use the definition from the external style sheet. For example, if a web page uses both an external and internal stylesheet that both contains definitions for the <h3> tag, the definition for the <h3> tag used in the external style sheet will be used on the web page. (more…)

CSS Tutorial

Introduction to CSS

Before beginning with CSS, you should be comfortable with either HTML or XHTML. These languages are usually interwoven with CSS.

Originally, HTML was designed to define elements in a document or web page. For example, a paragraph would be known as <p>, a link would be <a>, and so forth.

As internet browsers kept adding more formatting tags (such as the <font> tag), it became difficult and cumbersome to style a web page due to the lack of a single coherent standard. CSS (Cascading Style Sheets) were introduced by the World Wide Web Consortium (W3C) to remedy this problem.

CSS is supported by all major browsers.

What Are Style Sheets?

Style sheets are separate documents that define how our HTML elements should appear. For example, should all text in tables be presented as a blue font color?

Style sheets allow us to centralize the styling elements of our entire website into one document. This can save a lot of work when you want to change your layouts, fonts, and more.

External style sheets are usually saved in .css format.

CSS Tutorial

The “Style” Attribute in CSS

The “style” attribute is an HTML attribute often used in conjunction with CSS syntax.

The “style” attribute can be applied to almost HTML element from the <table> to the <body> tag.

The basic syntax for the style attribute is:

<div style="">

In our example, we used the “div” HTML element. Once again, the “style” attribute can be applied to any HTML element — not just the “div” element.

Inside the quotation marks for the style attribute, we place any CSS code.

Here’s another example:

<div style="font-size:12pt;">

This time, we used a little bit of CSS code (which we will explain later in the tutorial). Notice we ended with a semi-colon. This is used to separate CSS statements. We can apply multiple CSS statements in one “style” attribute by separating them with semi-colons as follows:

<div style="font-size:12pt;font-weight:bold;">

The individual CSS code will be explained later in the tutorial.

The “style” attribute can be used on nearly every HTML element. However, the “style” attribute is not recommended. It’s better to use an external style sheet to store and centralize all of your CSS code. A single style sheet can reduce page load times and make it easier to manage your website.

CSS Syntax

We will now begin to use external style sheets. To start with CSS, just create a file with the extension “.css” to begin.

CSS syntax is composed of the selector, the property, and the value.

It’s usually written in this form:

selector {property: value}

The “selector” is the HTML element you want to modify. This can be the <body> tag, the <font> tag, and more. The “property” is the attribute to modify and the “value” is the modification applied to the property.

Let’s use a real world CSS example:

font {color:#000000}

#000000 is the hexidecimal (hex) code for the color “black.” Please refer to our HTML text formatting tutorial for a more in-depth explanation on hex codes.

The above CSS code will turn all text enclosed in the <font> tag to be colored black. (more…)

What’s Your Online Reputation Saying About You?

Before graduation, most students will receive some form of advice on searching for a job. Whether it’s from a career counsellor, a professor, or a parent, students are usually told about the importance of things such as networking, writing personalized cover letters, and dressing for success. However, with over 90% of hiring professionals using social media sites to screen prospective employees, relying solely on your application to make a good first impression is no longer enough. Students must be aware of their online reputation, and the message that it’s sending to prospective employers.

Don’t let the news that employers may be looking you up online scare you. Instead, use it as an opportunity to make yourself stand out from the crowd.

“Hiding” Online Isn’t the Answer

Effectively managing your reputation means more than maximizing all of your security settings. While you should certainly start by visiting your Facebook profile to see what type of content is visible to others, hiding behind a fake name can have consequences. Kashmir Hill warns that it is increasingly “expected that everyone is on Facebook in some capacity,” and that it can look quite suspicious if someone isn’t using the site. Similarly, a locked Twitter account where tweets aren’t visible to the public may make employers wonder what exactly you have to hide.

Take Control of Your Reputation

Make your online reputation work for you. 68% of hiring professionals surveyed in a Reppler study responded that they have hired a candidate because of what they saw about them on a social networking site. Get a sense of what others find when they search for you by Googling your own name. Managing your reputation involves not only what you’re sharing, but also what others are sharing about you, so keep on top of your personal brand by setting up a Google Alert that will email you when new search results appear for your name. Students can also sign up for the free service provided by Reppler, which monitors your social media presence across Twitter, Facebook, and LinkedIn to identify potential issues and risks. Reppler can also show you how you are likely perceived across your social networks, such as whether you use a positive or negative tone, and the words you use most often.

Building a positive online reputation requires an investment of your time, so don’t expect it can be done overnight. Show prospective employers that you are interested in your chosen field of work by using Twitter to share relevant articles and information with your followers. Take advantage of the “Recommendations” feature on LinkedIn, which allows past employers, co-workers, and peers to write brief recommendations about your work. If you don’t have a LinkedIn profile, my advice is to sign up for one right away! The professional social network is free to join with a basic account, and is a great platform for prospective employers to check out your education and work or volunteer history. (If you want to enjoy LinkedIn’s advanced features a Job Seeker account starts at US $15.95 / month, but from my experience the basic account is more than enough for the average student.) I have also created a Flavors.me page (a service similar to About.me) that acts like digital business card: it features a brief introduction to who I am and directs people to my Twitter and LinkedIn pages.

Online = Forever

Remember that the things you post online shape how other people perceive you. What might seem like a fun or harmless post today could resurface in the future with damaging results. Reputation management shouldn’t end as soon as you find your first job. Not only will a positive online reputation help you the next time you need to search for a position, but it’s also important to ensuring you keep the job you do have. An employee is a representative of the company they work for, and any inappropriate photos or comments you post not only reflect poorly on you, but also on the company.