Posts tagged Web Design

Basics of CSS Part – #9

Today we’re going to talk about list styles. Lists are a vital commodity to web site creation. Most side-navigation menus and inline menus are actually lists that are simply listing the things we want them to. From there, we can add styles to these lists and manipulate them however we please.

Lists

In HTML there are two types of lists:

  • Ordered Lists <ol>
  • Unordered Lists <ul>

Ordered Lists are usually marked with numbers or letters whereas Unordered Lists are usually marked with bullets or squares.

List Type

We can change how a list looks by using the list-style-type property. Consider the following code:

ul {list-style-type:circle;}
ol {list-style-type:upper-roman;}

The CSS code above will make all ul elements have a list style type of a circle and all ol elements have a list style type of upper roman numerals. The output will look like the following:

  • Item 1
  • Item 2
  1. Item 1
  2. Item 2

Properties

We can have a few properties for list types and those properties operate the same way the background properties

Property Description Values
list-style This is the all inclusive property where you can define all of the values list-style-type
list-style-image
list-style-position
list-style-type This property will define type of list style you wish to have in the <li> element. none
disc
circle
square
decimal
decimal-leading-zero
armenian
georgian
lower-alpha
upper-alpha
lower-greek
lower-latin
upper-latin
lower-roman
upper-roman
hebrew
cjk-ideographic
hiragana
hiragana-iroha
katakana
katakana-iroha
list-style-image This property will allow you to define an image as the list marker. url(image url)
none
list-style-position This property will allow you to specify whether you want the list to be inside or outside the content flow. inside
outside

We can also narrow down the list-style and list-style-type properties for each list element.

Unordered Lists

For unordered lists we can use the following values:

  • circle
  • disc
  • square
  • none

Technically we can use any of the values listed in the table above, however, the purpose of the unordered list would cease to exist.

Ordered Lists

We can have many options for the ordered list. Out of the 23 values we posted for list-style-type, only three were solely for unordered lists. We can use the following values:

  1. decimal
  2. decimal-leading-zero
  3. armenian
  4. georgian
  5. lower-aplha
  6. upper-alpha
  7. lower-greek
  8. upper-greek
  9. lower-latin
  1. upper-latin
  2. lower-roman
  3. upper-roman
  4. hebrew
  5. cjk-ideographic
  6. hiragana
  7. hiragana-iroha
  8. katakana
  9. katakanap-iroha

Using images with lists

Using images can spice up just a standard web page by a lot. It is very easy to create your own bullet, circle, square, or a small arrow pointing toward the item you are showing in the list. We can use the all-inclusive,

list-style:url ("image/bullet.png");
/*OR*/
list-style-image:url ("image/bullet.png");

This will replace the default bullet in the unordered list with an image of our choice.

To see these properties in action feel free to download lists.zip(9.75KB)

Basics of XHTML Part – #6

Today we are going to talk about List types in HTML. There are three lists that HTML supports:

  • Unordered Lists
  • Ordered Lists
  • Definition Lists

Unordered Lists

An unordered List is a list that have bullets in front of the list item (normally little black circles). The Unordered List starts with a <ul> tag and each new item starts with an <li> tag. The syntax is as follows:

<ul>
     <li>Item 1</li>
     <li>Item 2</li>
     <li>Item 3</li>
</ul>

The browser output will look this:

  • Item 1
  • Item 2
  • Item 3

You can put unordered lists inside paragraphs, line breaks, links, images, lists, and other non-block level elements. We would use an unordered list if we wanted to create a list that didn’t have any specific order, like a grocery shopping list.

We can also change how the bullets look without using style sheets or inline css. Within the <ul> tag we simply add an attribute called type and add the value we want. Here are the values we can put:

  1. disc
  2. circle
  3. square

Here is the syntax:

<ul type="disc">
     <li>Item 1</li>
     <li>Item 2</li>
</ul>
<ul type="circle">
     <li>Item 1</li>
     <li>Item 2</li>
</ul>
<ul type="square">
     <li>Item 1</li>
     <li>Item 2</li>
</ul>

The browser output is like this:


  • Item 1
  • Item 2
  • Item 1
  • Item 2
  • Item 1
  • Item 2

Ordered List

An ordered list is a list that is marked with numbers instead of bullets. The ordered list starts with an <ol> tag and then each list item (like the unordered list) has the <li> tag around the item. The syntax is as follows:

<ol>
     <li>Item 1</li>
     <li>Item 2</li>
     <li>Item 3</li>
</ol>

The browser output will look this:

  1. Item 1
  2. Item 2
  3. Item 3

You can put unordered lists inside paragraphs, line breaks, links, images, lists, and other non-block level elements. We would use an ordered list if we wanted to create a list thathas a specific order. A good example would be if you were creating a step by step guide.

Like the unordered list, there is a way to change the list type without using styles or inline css to an ordered list. Here is the syntax:

<ol type="A"> <!--Upper Alpha-->
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="a"> <!--Lower Alpha-->
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="I"> <!--Upper Roman-->
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="i"> <!--Lower Roman-->
<li>Item 1</li>
<li>Item 2</li>
</ol>

The browser output will look like this:


  1. Item 1
  2. Item 2
  1. Item 1
  2. Item 2
  1. Item 1
  2. Item 2
  1. Item 1
  2. Item 2

Definition List

A definition list isn’t really a list but rather a list of items (terms) and each item (term) has a description.

The definition list begins with an <dl> (definition list) tag.

Each term starts with a <dt> (definition term) tag.

Each term description starts with a <dd> (definition description) tag.

The browser output will look like this:


Item 1
Description 1
Item 2
Description 2
Item 3
Description 3

Basics of XHTML Part – #5

Today we’re going to talk about HTML Tables! Tables were created in May of 1996 as in update to HTML 2.0. Since then, tables were a way for us to layout our websites and/or information in a document. Frames became popular with HTML 3.0, HTML 3.2, and especially HTML 4.0. After Framesets fizzled out tables became the preferred method of website creation.

Now, websites are being created with intricate server side programs and CSS that will write HTML for you. Despite these improvements for website creation, if you just do a simple google search for a website, you’ll see that some are still made using tables. You can read all about the History of HTML by reading the wiki article on it.

Tables is a good starting point to understanding site layout and the flow of the page, so it’s still good to know!

Tables

Tables are defined by creating a <table> tag and then a <tr> and then a <td> So the order is as follows:

  1. table
  2. tr (table row)
  3. td (table cell)

The general syntax for tables is as follows:

<html>
<head>
</head>
<body>
<table>
     <tr>
          <td>table cell</td>
          <td>table cell</td>
     </tr>
</table>
row 1 cell 1 row 1 cell 2
row 2 cell 1 row 2 cell 2

The example above in the form of HTML would be like the following:

<table border="1">
     <tr>
          <td>row 1 cell 1</td>
          <td>row 1 cell 2</td>
     </tr>
     <tr>
          <td>row 2 cell 1</td>
          <td>row 2 cell 2</td>
     </tr>
</table>

Border Attribute

The border attribute is an attribute that will display (or not display) a border around the <table>, <tr>, and <td> tags – basically around all elements of a table. If, for example, you wanted to create a table with no border then you would do the following:

<table border="0">
     <tr>
          <td></td>
          <td></td>
     </tr>
</table>

You can substitute the 0 for any integer that is wanted. Consider the table example we made before the Border Attribute title. That has a border=”1″.

row 1 cell 1 row 1 cell 2
row 2 cell 1 row 2 cell 2

This is the same table but with a border of 5.

Table Headings

Table Headings are defined by the use of <th> tags. These are usually used to title rows/columns in the table and are used in place of <td> to define the cell. Consider the following:

<table border="0">
     <tr> <!--Table headings-->
          <th>Table Heading</th>
          <th>Table Heading</th>
     </tr>
     <tr>
          <td>Table Cell</td>
          <td>Table Cell</td>
     </tr>
     <tr>
          <td>This is an example</td>
          <td>This is an example</td>
     </tr>
</table>

The code above would look like this:

Table Heading Table Heading
Table Cell Table Cell
This is an example This is an example

Cell Spanning

Sometimes you may need a single cell to span more than 1 column or row. For this we use the colspan and rowspan attributes on the td or th tags.

<table>
     <tr>
          <th rowspan="2">Name</th>
          <th colspan="2">Phone Number</th>
     </tr>
     <tr>
          <th>Home</th>
          <th>Mobile</th>
     <tr>
     <tr>
          <td>John Smith</td>
          <td>555-1234</td>
          <td>555-4321</td>
     </tr>
     <tr>
          <td>Bob Jones</td>
          <td>555-2943</td>
          <td>555-4929</td>
     </tr>
</table>

The above code would look like this:

Name Phone Number
Home Mobile
John Smith 555-1234 555-4321
Bob Jones 555-2943 555-4929

Cell Spacing and Cell Padding

Cell Spacing is used to create space between cells.
Cell Padding is used to create space between the cell content and the border of the cell.

Both cellspacing and cellpadding are attributes for the table tag. Here is an example of a table with a cellspacing=”10″:

Table Heading Table Heading
Table Cell Table Cell
This is an example This is an example

and here is a table with cellpadding=”10″:

Table Heading Table Heading
Table Cell Table Cell
This is an example This is an example

Alignment

The align attribute for td and th tags can be used with the values left, right, center or justify, to specify how the contents of the cell should be aligned. Justify spaces the words in the cell so that each line is an equal width. If an align attribute is not used, the default alignment is left, unless otherwise specified by the CSS.

Basics of XHTML Part – #4

Basics of HTML Part #3 is good to know before continuing on with this tutorial!

Today we’re going to talk about the img tag and the src attribute. This very important because this element allows us to input images in our web page and also input images from another web server or folder on our web server.

The Image Tag

There is something different about this <img> tag is that the closing tag is not </img>. This is known as a self-closing element or an empty element. These empty elements contain attributes only and no closing tag.

The “src” attribute

To properly display an image on a web page, we need the src attribute (which stands for source) which contains the relative or absolute link to the image you wish to attach. Without this attribute we would not be able to display an image because there would be no source.

Standard Hosting

The syntax for the img element is as follows:

<img src="url" />
<!--The image above-->
<img src="http://www.atomicpages.net/images/standard.jpg" />

Se have our basic syntax for the image element and the example provided is points toward the image location which has an image name of “standard.jpg” which is in the folder “images” on “http://www.atomicpages.net”
that has the URL of “http://www.atomicpages.net/images/standard.jpg”.

The image element will place the image where ever the <img> is place. If that happens to be in the middle of a paragraph or in some arbitrary place on your web page, then it will be placed where ever the element is placed in your source code.

The “alt” Attribute

The alt attribute is important to have for a few reasons.

First, this alt attribute will display the text if a visitor on your web site has images turned off or they are using a text-only browser. This will accurately tell the user what they are missing if the page cannot load the images. Note: the alt attribute is not used as an image description or a summary of what the image is or what it is about.

Second, the alt attribute is good to have for Search Engine Optimization (SEO). Web bots that crawl your web site cannot see the images.

Third, the addition of the alt attribute will make your web page W3C compliant and your web page will validate when checked by the W3C HTML Validator.

Here is an example of useage for the alt attribute:

<img src="url" alt="Alternative text" />
<!--Example-->
<img src="http://www.atomicpages.net/images/standard.jpg"
alt="Standard Hosting" />

“height” and “width” attributes

Height and Width attributes can be used in the place of inline css or css in general. These attributes specify the dimensions of the image. These attributes will usually come after the src attribute. The syntax is as follows:

<img src="url" height="in px" width="in px" alt="" />
<!--Example-->
<img src="http://www.atomicpages.net/images/standard.jpg"
height="148" width="300" alt="Standard Hosting" />

The height and width attributes define the image size in terms of pixels (px) without you having to write px after the integer.

Alliteratively, you can use inline css to define an images dimensions like so:

<img src="http://www.atomicpages.net/images/standard.jpg"
style="height:148px; width:300px; alt="Standard Hosting" />

Images and Links

In Basics of HTML Part #3 we discussed links and anchors. We can actually combine links and images to make clickable images that will take us to a larger image or another place on our web page.

Consider the following code:

<img src="http://www.atomicpages.net/images/standard.jpg"
height="148" width="300" alt="Standard Hosting" />

This will correctly display the image we want; however, if we wanted to make this image one that was clickable then we would do the following:

<a href="http://www.atomicpages.net/hosting.php">
<img src="http://www.atomicpages.net/images/standard.jpg"
height="148" width="300" alt="Standard Hosting" />
</a>



This would make the image clickable and once you clicked on the image it would take you to http://www.atomicpages.net/hosting.php If we wanted to use an image that would link to another image or a larger image then we would do the following:

<a href="url to different/larger image">
<img src="url to image you want to display" height="" width="" alt="" />
</a>
<!--Example-->
<a href="http://www.atomicpages.net/images/standard.jpg">
<img src="http://www.atomicpages.net/images/standard-small.jpg"
height="74" width="150" alt="Standard Hosting" />
</a>

Click

Advanced CSS Part -#7

Today we’re going to create a top navigation menu and side menu in CSS. This is like any website menu that we would see on most websites.

Inline Menu

This is an example of a website menu:

Menu

We can see that the menu is entirely inline and is actually really just an unordered list. Consider the following code:

#menu {
     background-color:#4c4c4c;
     height:30px;
     font-size:30px;
     font-weight:700;
     padding:5px 0px;
}
#menu ul {list-style:none;}
#menu li {
     display:inline;
     padding:0px 10px;
}
<div id="menu">
     <ul>
          <li><a href="url">Link</a></li>
          <li><a href="url">Link</a></li>
          <li><a href="url">Link</a></li>
          <li><a href="url">Link</a></li>
     </ul>
</div>

The CSS is setting the styles for the navigation menu… We have our ID selector #menu that is creating a background of #4c4c4c (grey), a height of 30px, a font size of 30px, a font weight of 700 (in other words, bold), and a padding of 5px that applies to the top and bottom ONLY.

#menu ul is basically saying that all <ul> elements inside of the ID #menu will have a list-style of none.

#menu li is saying that all <li> elements within the ID #menu will be displayed as inline elements (no breaks before or after the element, refer to the Display Property for more information) and will apply a 10px padding to the left and right sides ONLY.

Vertical Menu

A vertical menu is a menu that is, well, vertical.

Side Navigation

Side Menus are easier to make than inline menus. Consider the following code:

#side-nav {
     background-color:#4c4c4c;
     display:block;
     width:150px;
}
#side-nav ul {
     list-style-image:url("images/bullet.png");
     margin:10px;
}
#side-nav li {
     padding:5px 0px;
     border-bottom:1px solid #3b3b3b;
}
#side-nav.no-border {border:none;}
<div id="side-nav">
     <ul>
          <li><a href="url">Link</a></li>
          <li><a href="url">Link</a></li>
          <li><a href="url">Link</a></li>
          <li class="no-border"><a href="url">Link</a></li>
     </ul>
</div>

So we have our ID selector side-nav that is creating the background color of #4c4c4c (grey), displaying the selector as a block element and a width of 150px. Note: since only the width is defined, we can have an unlimited height.

Next, we have our selector that is saying that all <ul> elements within the side-nav selector will have a list style image of “bullet.png” and will have a 10px margin around all sides.

Finally, we have our selector that is saying all <li> elements within the side-nav selector will have a top and bottom padding of 5px ONLY and a bottom border that is 1px wide, solid, and the color #3b3b3b. There is something interesting, however; there is an additional selector defined that states a border is none which we used on the last <li> element of our vertical menu. This will make the menu look better, or at least more symmetrical.

I recommend you downloading Menu.zip (4.46KB) to see these menus in action!

Advanced CSS – Part #6

Pseudo-elements are used to add special effects to some html elements.

Pseudo-elements are very much like pseudo-classes. The syntax for pseudo-elements is like pseudo-classes:

selector:pseudo-element {property:value;}

We can also use class selectors with our pseudo-elements:

selector.class:pseudo-element {property:value;}

Pseudo-elements

Since pseudo-elements exist to give some html elements some flair, we have a few special pseudo-elements that we need to be familiar with.

:first-line

As the name implies, this pseudo-element adds special styles to the first line of text. We can only use this pseudo-element with block-level elements (see Display Property for more details).

p:first-line {
     color:#ff9300;
     font-style:italic;
}

The above code would make the first line of text color turn to atomicpages orange and then change the first line of text to be italic. There are, however, certain properties that are not allowed when using the :first-line property. We can use the following:

  1. all font properties
  2. color
  3. all background properties
  4. text-decoration
  5. clear
  6. text-transform
  7. letter-spacing
  8. word-spacing
  9. vertical-align
  10. line-height

These are the only properties that are valid to use with the :first-line pseudo-element!

:first-letter

This pseudo-element applies unique styles to the first letter of text. Consider the following code:

p.a:first-letter {
     background:#fff url("images/fancy_a.gif") no-repeat;
     border:1px solid #ff9300;
     margin-left:25px;
}

This will load the first image of all p elements with the class “a” so:

<p class="a">very fancy image at the beginning of this makes this
sentence seem much more grandiloquent that it really is!</p>

This fancy_a.gif will also have a border of 1px which is solid and atomicpages orange and will have a left margin of 25px.

Like the :first-line pseudo-element, there are restrictions on which properties can be used with this pseudo-element.

  1. all font properties
  2. color
  3. all background properties
  4. text-decoration
  5. clear
  6. text-transform
  7. letter-spacing
  8. word-spacing
  9. vertical-align
  10. line-height
  11. margin properties
  12. padding properties
  13. float

:before

This pseudo-element is used to insert content before and element is rendered by the browser. Consider the following code:

span:before {background:#fff url("images/fancy_a.gif") no-repeat;}

This is saying that before every span element there will be that fancy “A” that we define earlier in this tutorial.

:after

This pseudo-element is used to insert content after and element is rendered by the browser. Consider the following code:

h4:after {background:#fff url("images/fancy_b.gif") no-repeat;}

This is saying that after every h4 element there will be that fancy “B”.

Now what does that accomplish? Nothing very significant in this case but you can download pseudo-elements.zip (7.76 KB) to see these pseudo-elements in action!

Advanced CSS – Part #5

Pseudo-classes are little snippets of code that will add additional effects to some selectors.

Pseudo-classes

The syntax for Pseudo-classes is very much like the syntax for css:

selector {property:value;} /*CSS Syntax*/
selector:pseudo-class { /*Pseudo-class Syntax*/
     property:value;
     property:value;
}

:link, :visited, :active, :hover

A very widely used example of Pseudo-classes is adding styles to links. Consider the following:

a:link, a:visited {
     text-decoration:underline;
     color:#ff9300;
}
a:hover {
     text-decoration:none;
     color:#ff9300;
}

These are called “global link styles”, these are styles that will apply to any and all links on a page where this code is. We have our pseudo-classes a:link, a:visited, a:hover and each is doing something different.

1. a:link

a:link sets the styles for an unvisited link:

a:link {
     color:red;
     font-weight:bold;
}

2. a:visited

a:visited sets the styles for a visited link:

a:visited {
     color:blue;
     font-weight:bold;
}

3. a:hover

a:hover sets the styles for links that you mouse over:

a:hover {
     color:aqua;
     font-weight:bold;
     text-decoration:unerline;
}

4. a:active

This sets the styles for a link that is currently active:

a:active {
     color:coral;
     font-weight:bold;
     text-decoration:unerline;
}

Order

Order is key when using these particular pseudo-classes. When you write these styles you must follow the correct order to make it all work.

a:link { /*This must be first*/
     color:red;
     font-weight:bold;
}
a:visited {  /*This must be second*/
     color:coral;
     font-weight:bold;
}
a:hover {  /*This must be third*/
     text-decoration:unerline;
     color:blue;
     font-weight:bold;
}
a:active { /*This must be last*/
     color:green;
     font-weight:bold;
}

We can also group the pseudo-classes together like this:

a:link, a:visited {
     text-decoraton:none;
     color:#ff9300;
}
a:hover, a:active {
     text-decoration:unerline;
     color:coral;
}

Like other CSS selectors, we can add a class selector to the Pseudo-classes, this would enable us to apply these styles any where on our web page if we desired it to be so.

selector.class:pseudo-class {
     property:value;
     property:value;
}
a.fancy:link, a.fancy:visited {
     text-decoration:underline;
     color:#ff9300;
}

This class fancy will make a link and you visit that link that we create, it will be underlined and be that atomicpages orange color.

:first-child

The first-child pseudo-class is as it sounds. This will apply any styles that you define to the first-child element of a parent element. Consider the following code:

body {
     margin:auto;
     width:1000px;
     background-color:#4c4c4c;
     font:normal 11px Verdana, "Times New Roman", sans serif;
     color:#fff;
}
p:first-child {
     color:blue;
     text-decoration:underline;
     font-weight:700;
}

We can use the first-child pseudo-class in some very helpful ways too! If, for instance, you wanted to apply a style that would make the first paragraph unique, we could use the first-child pseudo-class to achieve this goal. Consider the following:

.fancy p:first-child {
     color:red;
     font-style:italic;
}

This would set the first paragraph of the class “fancy” to be red and italic and all subsequent paragraphs to be whatever we set the styles to.

If you want to see pseudo classes in action feel free to check out pseudo-casses.zip (1.88KB) and see these examples in action!

CSS Reference

Quick Selection

Background Property

Properties Definitions Examples CSS
background Sets all background properties: background:#4c4c4c url("image/gloss.png") top center repeat-x; 1
background-attachment Sets whether the image scrolls or is fixed on a page: background-attachment:fixed; 1
background-color Sets the background color of an element: background:blue; 1
background-image Sets the background image on an element: background-image:url("image/header.jpg"); 1
background-position Sets the position of an element: background-position:center; 1
background-repeat Sets how the background will repeat: background-repeat:repeat; 1

Border and Outline Properties

Properties Definitions Examples CSS
border Sets all four definitions in one declaration border:1px inset blue; 1
border-style Sets the border style for all four sides border-style:groove; 2
border-width Sets the border width for all four sides border-width:thick; 1
border-color Sets the border color for all four sides border-color:#ff9300; 2
border-top Sets the top border in one declaration border-top:thin solid #fff; 1
border-top-width Sets the top border width border-top-width:medium; 1
border-top-color Sets the top border color border-top-color:purple; 2
border-top-style Sets the top border style border-top-style:ridge; 2
border-right Sets the right border in one declaration border-right:10px dotted orange; 1
border-right-color Sets the right border color border-right-color:#000; 2
border-right-style Sets the right border style border-right-width:dashed; 2
border-right-width Sets the right border width border-right-width:2px; 1
border-bottom Sets the bottom border in one declaration border-bottom:3px hidden transparent; 1
border-bottom-color Sets the bottom border color border-bottom-color:#470b0b; 2
border-bottom-style Sets the bottom border style border-bottom-style:none; 2
border-bottom-width Sets the bottom border width border-bottom-width:4px; 1
border-left Sets the left border in one declaration border-left:6px outset white; 1
border-left-color Sets the left border color border-left-color:#fff1d8; 2
border-left-style Sets the left border style border-left-style:inherit; 2
border-left-width Sets the left border width border-left-width:8px; 1
outline Sets the outline in one declaration outline:3px dotted green; 2
outline-color Sets the outline color outline-color:blue; 2
outline-style Sets the outline style outline-style:inset; 2
outline-width Sets the outline width outline-width:thin; 2

Dimensions

Properties Definitions Examples CSS
width Sets the width of an element width:1000px; 1
max-width Sets the maximum width of an element max-width:75% 2
min-width Sets the minimum width of an element min-width:20em; 2
height Sets the height of an element height:600px; 1
max-height Sets the maximum height of an element max-height:50%; 2
min-height Sets the minimum height of an element min-height:2em; 2

Font Properties

Properties Definitions Examples CSS
font Sets all the font properties in one declaration font:11px bold italic Verdana, Geneva, sans-serif 1
font-family Sets the font family font-family:Georgia, "Times New Roman", Times, serif; 1
font-size Sets the font size font-size:18px; 1
font-style Sets the font style font-style:oblique; 1
font-variant Sets the font variant font-variant:small-caps; 1
font-weight Sets the font weight (boldness) font-weight:700; 1

List Properties

Properties Definitions Examples CSS
list-style Sets all properties in one declaration list-style:circle outside url(“list.gif”); 1
list-style-image Sets list image list-style-image:url("blue.png"); 1
list-style-position Sets whether position is inside or outside the flow of the list list-style-position:inside; 1
list-style-type Sets list type list-style-type:none; 1

Margin Properties

Properties Definitions Examples CSS
margin Sets all four sides of the margin in one declaration margin:25px 3px 5px 15px; 1
margin-top Sets the top margin margin-top:10px; 1
margin-right Sets the right margin margin-right:15px; 1
margin-bottom Sets the bottom margin margin-bottom:50px; 1
margin-left Sets the left margin margin-left:25px; 1

Padding Properties

Properties Definitions Examples CSS
padding Sets all four sides of the padding in one declaration padding:15px 30px; 1
padding-top Sets the top padding padding-top:30px; 1
padding-right Sets the right padding padding:right:10px; 1
padding-bottom Sets the bottom padding padding-bottom:50px; 1
padding-left Sets the left padding padding-left:25px; 1

Positioning Properties

Properties Definitions Examples CSS
bottom Sets the bottom margin edge for a box that is positioned bottom:30px; 2
clear Sets which sides floated elements are not allowed clear:both; 1
clip Clips an element that is absolutely positioned clip:rect(30px 0px 60px 90px); 2
cursor Specifies the cursor to be displayed within a certain element cursor:crosshair; 2
display Specifies which type of box an element should have display:inline; 1
float Specifies whether or not a box should float left or right float:left; 1
left Sets the left margin edge for a box that is positioned left:45px; 2
overflow Sets what happens if content were to overflow its box overflow:scroll; 2
position Sets how an element is positioned position:relative; 2
right Sets the right margin edge for a box that is positioned right:15px; 2
top Sets the top margin edge for a box that is positioned top:20px; 2
visibility Specifies whether or not an element is visible visibility:hidden; 2
z-index Specifies the stacking order of elements z-index:-1; 2

Print Properties

Properties Definitions Examples CSS
page-break-before Sets the page break before an element page-break-before:always; 2
page-break-after Sets the page break after an element page-break-after:auto; 2
page-break-inside Sets the page break inside an element page-break-inside:avoid; 2
orphans Sets the minimum number of lines there must be and the bottom of an element after a page break orphans:2; 2
windows Sets the minimum number of lines there must be and the top of an element after a page break windows:10; 2

Table Properties

Properties Definitions Examples CSS
border-collapse Specifies whether or not the border should be collapsed border-collapse:collapse; 2
border-spacing Specifies distance between adjacent cell borders border-spacing:15pt; 2
caption-side Sets placement of table caption caption-side:center; 2
empty-cells Sets whether or not borders of empty cells are displayed empty-cells:hide; 2
table-layout Changes the algorithm used for the table layout table-layout:fixed; 2

Text Properties

Properties Definitions Examples CSS
color Sets the color of text color:#ff9300; 1
direction Sets the writing direction of text direction:right; 2
letter-spacing Specifies distance between letters of text letter-spacing:.75em; 1
line-height Specifies distance between lines of text line-height:15px; 1
text-align Sets the alignment of text text-align:center; 1
text-decoration Specifies the decoration added to text text-decoration:overline; 1
text-indent Sets indentation of first line in a text block text-indent:25px; 1
text-shadow Sets the shadow text may have text-shadow:;#ccc 15px -10px 8px; 2
text-transform Controls the capitalization of text text-transform:uppercase; 1
vertical-align Sets the vertical alignment of an element vertical-align:middle; 1
white-space Sets how the white space inside an element will be used white-space:pre-wrap; 1
word-spacing Specifies the distance between words in a text block word-spacing:30px; 1

Pseudo-classes and Pseudo-elements

Properties Definitions Examples CSS
:active Applies specified style to an active element a:active {<styles>} 1
:after Adds content after an element a:after {<styles>} 2
:before Adds content before an element a:before {<styles>} 2
:first-child Adds specified styles to the first child element body:first-child {<styles>} 2
:first-letter Adds specified styles to the first letter of an element p:first-letter {<styles>} 1
:first-line Adds specified styles to the first line of text p:first-line {<styles>} 1
:focus Adds a focus to keyboard input input:focus {<styles>} 2
:hover Applies styles to an element that you hover over a:hover {<styles>} 1
:lang Adds style to an element with a lang attribute q:lang {<styles>} 2
:link Applies styles to a unvisited link a:link {<styles>} 1
:visited Applies styles to a link that has been visited a:visited {<styles>} 1

All about BB Code

BB Code is a common way for format blog posts, forum posts, and comments on those posts. BB Code is an acronym for bulletin board code. If you are familiar with HTML code then BB Code will be very easy for you to understand. If not then need not worry, we will be covering all of the essential info you’ll need to know.

BB Code is an alternative to using HTML in user input forms. BB Code is a “safer” alternative to HTML, for when you have unknown users making posts on your site and you want to protect from the users trying to do anything malicious. Ultimately the BB Code, is converted into normal html, usually by a php script, so that the browser can interpret it.

Like HTML, BB Code has tags or key words or characters placed within a tag that contain a special meaning. Example:

HTML/CSS BB CODE
<b> bold text [b]bold text[/b]
<i> italic text [i]italic text[/i]
<u> underline text [u]underlined text[/u]
text-decoration:line-through; strikethrough text [s]line-through text[/s]
font-size:value; some text [size={number}]text[/size]
color; some text [color={color}]text[/color]
text-align:center; some text [center]centered text[/center]
<blockquote>
some text

[quote]blockquote[/quote]
<a href="url"> this is a link [url={url}]link title here[/url]
<img src="img" /> {image} [img]{url}[/img]

<img src="img" height="#" width="#" />

Resized Image

[img{width}x{height}]{url}[/img]

<ul> unordered list [ul][li]{text}[/li]…[/ul]
<ol> ordered list [ol][li]{text}[/li]…[/ol]
<code> monospace text [code]{text}[/code]
<table><tr><td></td></tr></table> [table][tr][td][/td][/tr][/table]

For those that know HTML you see the similarities. For those you who are not, we can see how certain words or characters are encased in brackets [] and they have a special meaning. An alternative to BB Code is a HTML Filter that will not allow javascript and other tags.

Differences between HTML and BB Code

HTML BB CODE
Angled brackets <> Rectangular brackets []
Allows inline CSS by use of the style attribute Does not allow any inline CSS to be used
Chances of executing JavaScript or breaking the layout of a website No chance of executing JavaScript or breaking the layout of the site
Formatting is very picky and cannot be changed Formatting is simple and easy to understand and to change
There is a standard There is not a standard

BB Code is used in many forum softwares and content management systems.

Advanced CSS – Part #4

In this tutorial we’re going to talk about the float property. For this tutorial you will need to be familiar with the Basics of CSS and you should be familiar with the Advanced CSS tutorials until this point.

Float Property

The float property allows for an element to be pushed to the left or the right so other elements can wrap around it. Floated elements can only be moves horizontally (left or right). All floated elements will move as far right or as far left as it possibly can; this is dependent upon the nature of the container that the element is in.

Values

  1. left – floats element to the left
  2. right – floats element to the right
  3. none – specifies no floating

Consider the following code:

body {
     margin:auto;
     width:1000px;
     background-color:#4c4c4c;
     font:verdana, "Times New Roman", san-serif;
     font-size:11px;
     color:#fff;
}
#container {
     width:300px;
     background:transparent url('image/img.jpg') repeat-x;
     min-height:125px;
     float:right;
}

We have made the body element have a width of 1000px (the rest of the styles are irrelevant) and then we defined an ID selector that has a width of 300px and a min-height of 125px (it has to be at least 125px tall) and this element will be pushed to the edge of the right side of the container.

Since floated elements allow other elements to wrap around the floated element. All elements before the float property will not be affected, however, all element thereafter the float property will be affected. Consider the following code:

body { /*...*/ }
#container {
     width:300px;
     background:transparent url('image/img.jpg') repeat-x;
     min-height:125px;
     float:right;
}
.float-right {float:right;}
<html>
<body>
<div id="container">
     <p>This element will be on the right edge of the page that is
1000px across.</p>
</div>
<p>This is some text</p>
<img src="image/img.gif" height="100" width="100" alt="img"
class="float-right" />
<p>This is some text</p>
</body>
</html>

This example would allow for the text to wrap around “img.gif” no matter what size the image is (in the case of the example it is 100px by 100px).

Floating Elements

As we mentioned before, floating an element will push the element to the right or left side of the container if possible. Consider the following code:

.fancy {
     width:500px;
     float:left;
}
<h2>Title here</h2>
<div class="fancy">
<img src="img.gif" height="64" width="64" alt="img" />
<p>Description here</p>
</div>

This will put the image inside of an area of 500 px wide and infinitely tall (depending the amount of content in that class selector).

Clear Property

How do we “turn off” floated elements? The clear property specifies which sides of a floated element you want to keep clear of other floating elements.

Values

  1. left – clears the left side of the element
  2. right – clears the right side of the element
  3. both – clears both the left and right side of the element
  4. none – does not clear either side of the element

Consider the following code:

<html>
<head>
<style type="text/css">
.clearfix {clear:both;}
.fancy {
     width:500px;
     float:left;
     margin5px;
}
</style>
</head>
<body>
<div class="fancy">
<h2>Fancy Pictures</h2>
<img src="img.gif" height="64" width="64" alt="img" />
<img src="img2.gif" height="64" width="64" alt="img" />
<img src="img3.gif" height="64" width="64" alt="img" />
<img src="img4.gif" height="64" width="64" alt="img" />
<img src="img5.gif" height="64" width="64" alt="img" />
<p class="clearfix">Some explanatory text here</p>
<img src="img6.gif" height="64" width="64" alt="img" />
<img src="img7.gif" height="64" width="64" alt="img" />
</div>
</body>
</html>

In the code above, you would have all of the styles we defined in the fancy class and then a break of text where no floated element is allowed (neither left or right). This will clear a space for the explanatory text where no floated element will exist. This can be useful for adding more titles or text to the “fancy” class we created.

It is recommended that you download the float.zip (41.4KB) to see this property in action!