Posts tagged Web Design
Advanced CSS – Part #3
0Today we’re going to talk about advanced positioning techniques. This is a widely used property in CSS and it very useful! Positioning allows you to position an element, place one element behind another, and determine what happens when an element is too big.
The position of an element is controlled by top, right, bottom, and left properties. The stacking order of these elements is called the z-index property.
Position
As mentioned above, the position property allows us to specifically position an element on a web page, place one element behind or above another, and to determine what happens when an element is too big.
Properties to Know
- position
- top
- right
- bottom
- left
Note: the top, right, bottom, and left properties will NOT work unless a position property is defined first!
Values
- static
- fixed
- absolute
- relative
Static
All elements are positioned static by default. These are positioned by the normal flow of the web page and it is NOT changed by using the top, right, bottom, or left properties.
1 2 3 4 5 6 7 8 9
p.static {
position:static;
top:30px; /*This will not work*/
right:25px; /*This will not work*/
}
Fixed
A fixed position is relative to the browser window. Its place is literally locked in place and if you scroll, the element will remain exactly where it is.
1 2 3 4 5 6 7 8 9
p.fixed {
position:fixed;
top:30px;
right:25px;
}
The above code will place the element 30 px from the top of the browser window and 25 px to the right of the browser window while the position of the element is fixed. This means you can scroll the browser window and the element will literally be fixed on the page (it will not move). No matter where you are on the page, the element will always be visible.
If you use this fixed property, all other elements on the page will not know that it exists. The fixed element is removed from the normal flow of the web page so it does not impact any other elements. This also means that the fixed elements can overlap any other elements on the page.
Relative
A relative positioned element is relative to its “normal position” on the page. The relative positioned elements can be moved to overlap other elements; however, it is different in that the space for the normal flow of the page, is preserved. Even if two elements are over lapping the space for the elements is still preserved.
1 2 3 4 5 6 7 8 9
p.relative {
position:relative;
top:-50px;
right:10px;
}
Note: this will be made clearer via example in a small downloadable zip archive at the end of this tutorial. I strongly recommend downloading this tutorial!!
Absolute
Elements that are absolutely positioned are removed from the normal flow of the web page. Like the fixed value, all other elements on the web page don’t know this element exists. This means elements can easily overlap one another.
1 2 3 4 5 6 7 8 9
p.absolute {
position:absolute;
top:50px;
left:350px;
}
This element would be positioned in accordance to the html element of the web page. This would be exactly 50px from the top of the web page and 350px to the left of the web page as well.
If you wish to see these examples in action and read more about this material please click on the download button below.

position.zip
Size: 57.02 KB
Advanced CSS – Part #2
2Today we’re going to talk about the display and visibility properties of CSS. This is the second advanced tutorial and is intended for those of us that already understand the Basics of CSS.
Visibility
The Visibility of an element can be adjusted by using this visibility property. Let us say that we want to make a certain element invisible on a web page or that we want a certain to definitely be visible, we would use this visibility property.
Values
We can have three possible values for this visibility property.
- hidden – hides the element (these elements still take up space)
- visible – makes the element visible (default)
- collapse – this removes a table row or table column without affecting the table layout. If this is used on non-table elements they will render as “hidden”.
Note: no version of IE 8 or less supports the collapse value for this property. Consider the following code:
1
.hidden {visibility:hidden;}
This class would make the element “hidden” but the space for it would still exist, but it would show nothing. This might be a little confusing at first, however, it is very easy! This is some visible text that we can see. This is more text that we will write for the sake of this example. The more and more we write we see that there is this void in this paragraph and it feels as if something is missing, doesn’t it? You can actually look in the source code of this page and you will see this:
1 2 3 4 5
<span style="visibility:hidden;">This is some invisible text that
we cannot see but still takes up space inside
of the element.</span>
This was the code that was actually used to create this effect. We can see that visibility property makes the desired element invisible (hidden) but it still takes up space.
We won’t go into great detail about the collapse property and the visible value is default so this is not needed in order for an element to show. For example:
1 2 3 4 5 6 7 8 9 10 11
p.fancy {
color:#ff9300;
text-decoration:underline;
font-size:x-small;
visibility:visible; /*This is default, therefore not needed*/
}
Display
The display property defines how an element is displayed on the web page. The display property is very useful and particularly powerful. If you’ve ever wondered how to make those fancy top navigation menus like on this blog, we would use a certain value for the display property.
Values
- none – hides element completely (no box)
- block – creates a box (line breaks above and below)
- inline – creates inline element (no line breaks at all)
- inline-block – creates block but it is laid out as an inline box
- compact – basically this box will nest against another box is there is enough space
- inline-table – element will create a box with no breaks before or after the <table>
- list-item – creates list (like a ul) in a block but the li are inline elements
- run-in – your browser will create a block or inline box depending on how it is used 1
- table – this will behave like a table (a CSS alternative to th, td, and tr elements!)
- table-caption – behaves like a table caption
- table-header-group – behaves like a table header group
- table-row – behaves like a table row
- table-row-group – behaves like a table row group
- table-cell – behaves like a table cell
- table-column – behaves like a table column
- table-column-group – behaves like table column (like <colgroup>)
- table-footer – behaves like a table footer
- table-footer-group – behaves like a footer row group
As we can see there are many values we can have for the display property and each does something unique. These will take time to explain so I highly recommend you click on the download button below.
You may also want to check out Quirksmode for a very comprehensive overview of the display property.

display.zip
Size: 67.97 KB
1. This is only supported in the latest version of IE and Opera 9.2 and Opera 10. All other browsers don’t necessarily support this value. You can read all about the run-in value from W3C if you want to learn more about it.
Advanced CSS – Part #1
0Now that we have all of the Basics of CSS down pat, we can move onto more advanced methods of writing and implementing style sheets!
Today we’re going to talk about grouping and nesting selectors and dimensions.
Grouping and Nesting
You might find yourself with selectors having the same values inside of your internal or external style sheet. Maybe it is about a specific link within a certain area of your web site, heading elements, or just about anything else you would want to group.
Grouping
Grouping allows us to apply multiple properties and values to multiple selectors but in a condensed fashion.
Let us assume we have some code:
1 2 3 4 5 6 7
h1 {color:#ff9300;}
h3 {color:#ff9300;}
span {color:#ff9300;}
p {color:#ff9300;}
So we have everything within the h1, h3, span, and p elements is the color #ff9300. Since all of these elements have a common property we can group these elements like this:
1
h1, h3, span, p {color:#ff9300;}
This space saver will have the same effect but on multiple selectors. The single color property will be applied to all of these html elements. Note: grouping elements will apply all properties and values to the grouped elements. Example:
1 2 3 4 5 6 7 8 9 10 11
html, body, p, span, a:link, {
margin: 0;
padding: 0;
font:verdana, "Times New Roman", sans serif;
color:#ff9300;
}
This means margin:0; padding:0; font:verdana, “Times New Roman”, sans serif; and color#ff9300; will be applied to all of those selectors.
Nesting
Nesting will allow you to apply styles to a selector within a selector. Consider the following:
1 2 3 4 5 6 7 8 9 10 11
#fancy p {
background-color:#000;
font-weight:700;
text-decoration:none;
color:#ff9300;
}
So we have our ID selector with an extra selector after it. So if we have something with the ID selector such as:
1 2 3 4 5
<div id="fancy">
<p>Some fancy text here</p>
</div>
It is saying everything within the fancy ID that is inside of any p element will have all of those properties and values. We have used this type of nesting in earlier CSS tutorials.
Dimensions
We covered the width and height properties in the box model tutorial. We going to introduce a few new properties that we can use to further control how tall/wide an element is.
The Height property will set the height of the element and the Width property will set the width of the element. Consider the following code:
1 2 3 4 5 6 7
h2, h3 {
height:100px;
width:300px;
}
This will set all h2 and/or h3 elements to w height of 100px by 300px regardless of how much space it is taking up on the page. These two elements will always be this height. What if we wanted those two elements to be within a certain area of space?
Properties
- width – defines width (will always be)
- height – defines height (will always be)
- max-width – defines max width (cannot be bigger than)
- min-width – defines min width (will not be smaller than)
- max-height – defines max height (cannot be taller than)
- min-height – defines min height (will not be shorter than)
The last four properties are new to us. So let us improve on the previous code!
1 2 3 4 5 6 7
h2, h3 {
max-height:100px;
max-width:300px;
}
Given the code above, this will set the h2 and h3 elements to be no larger than 100px by 300px but can also be 0px by 0px if the element is empty (has no content).
Although it seems like this property would be somewhat useless, there has been situation where something a web page wasn’t working the way I wanted it to. Perhaps the top navigation menu was wrapping when I resized the browser windows and I wanted the entire page to keep its consistency. I would use a max-width and min-width property to define the space, lo and behold it worked!
For a very comprehensive overview of the above tutorial, please click on the download button below.

advanced-part1.zip
Size: 66.72 KB
Basics of CSS Part – #8
0Today we’re going to continue our journey into the Box Model. If you aren’t familiar with this box model, you should read about it!
Padding
Padding — defines the space between the element border and element content and will be the same color as the background color of the element.
If we recall that in the box model we have margins > borders > padding > content so Padding is tertiary. Let’s assume you have an HTML paragraph element:
1 2 3 4 5 6 7 8 9 10 11
<!--No Padding-->
<p style="background-color:#fff;">Lorem ipsum dolor sit amet,
consectetur adipiscing elit.</p>
<!--With padding-->
<p style="background-color:#fff; padding:10px;">Lorem ipsum dolor
sit amet, consectetur adipiscing elit.</p>
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
So what is different from the first line and the second line? The first line is without padding so the white background only fills to the end of the text instead the width of the box. The second line, however, spreads across the entire width of the box and it is a padding of 10px on all sides.
Padding works in very similar ways as the margin property except the margins are always invisible and the padding is based on the background of the element you are adding padding to.
Properties
Like margins, there are five possible properties we can use. They are the following:
- padding-bottom
- padding-left
- padding-top
- padding-right
- padding
The first four properties define each side for padding. For example, if you wanted to adjust the bottom and right padding for a certain element you could use the following:
1 2 3 4 5 6 7
p.element {
padding-bottom:3px;
padding-top:7px;
}
This will change the bottom padding of the element by 3px and the top padding of the element by 7px. Example:
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Remember that padding is basically an extension of the background of an element and you also need to take into account any other elements (whether above, below, left or right) that might get in the way of this padding. In theory, you could make an entire HTML and CSS website using only margins, borders, padding, and content.
Values
- em, px, pt – numeric values e.g. 1em, 15px, 2pt
- percent % – percent of the containing element e.g. 10% of 500px is 50px.
1 2 3 4 5 6 7 8 9
span.padding {
padding-top:2em;
padding-bottom:10px;
padding-right:16%;
}
All of the above are valid ways to define padding of our span element and class of padding.
Padding – All Inclusive
The all-inclusive padding property works the same way as the all-inclusive margin property. This singular padding property will define padding how ever we need it to using one property instead of writing out each side.
1
padding:15px 30px 45px 60px;
- top padding – 15px
- right padding – 30px
- bottom padding – 45px
- left padding – 60px
This example has four values for the padding property. The values start with padding-top and then go clockwise to padding-left. So if you think of clock and a new day, which always starts at 12 or the top of the clock, and then rotate clockwise the next 90° angle is at the right, then the 180° is at the bottom, and then the 270° is at the left. So it’s like looking at the clock at every 90° angle you get top, right, bottom, left.
1
padding:15px 30px 45px;
- top padding is 15px
- right and left padding is 30px
- bottom padding is 45px
This might come as a surprise to us because you would think they would group the [top and right] and [bottom and left] segments separately, however; we can see in this example that the padding-top is 15px and the padding-bottom is 45px. The left and right padding is grouped together because they just belong together. If someone asks, “when I say a word you think of something that is opposite to that” and they ask, “up” you’ll probably say “down” off the bat.
1
padding:15px 30px;
- top and bottom padding 15px
- right and left padding 30px
This might be more clear since there are only two values here. Naturally, we’d think [top and bottom] and [right and left] so the top and bottom padding will have a value of 15px whereas the right and left padding will have a value of 30px.
1
padding:15px;
- top, right, bottom, and left padding is 15px
One single value for the padding property will set all padding to that value, in our case 15px.
Web Design Tip #3 – Make your website lean and clean.
03.1 Optimize the page loading time
Images can really make a website look nice when used correctly, but nothing is more annoying than waiting for images to load when they are a way larger size than they need to be. The html width and height attributes let you re-size images, but the user still has to download the original image no matter how you re-sized it with the width and height attributes. Instead re-size your images to the correct size before embedding them into your webpage.
3.2 Don’t make an entire site using flash or java.
Some people think it’s okay to make their entire website just using flash. Flash can be a great thing browser embedded videos or games, but when people start making entire websites using flash, it just becomes annoying. You have to wait for the flash application to download and load before you can use it. And then once you finally get into it, you have all these extravagant animations that may look nice, but can just get annoying when you are trying to find what you’re looking for. Also, flash is unsupported on many mobile browsers like safari on the iPhone/iPod touch, so these users won’t be able to see your website at all.
