Archive for the ‘css’ Category

Class 3 – Default CSS style sheets for the major web browsers

Saturday, February 20th, 2010

Firefox

There are two default CSS style sheets that Firefox uses to display web pages.  Type these into the address bar of the browser to view them:

resource://gre/res/html.css
resource://gre/res/forms.css

Safari and Chrome

Apple’s Safari and Google’s Chrome browsers are built using an open-source layout engine known as Webkit.

Here is a link to the official WebKit source code for the default CSS style sheets of Safari and Chrome.

Internet Explorer

At this point in you will not be surprised to know that Microsoft Internet Explorer does not provide you access to it’s default CSS style sheet files.  Yet another reason not to use this browser.

Overriding the browsers’ default CSS style sheets

You’ll see in Firefox’s default CSS files that, by default, Firefox attaches an 8px margin on the <body> tag

body {
  display: block;
  margin: 8px;
}

If you don’t want an 8px margin on the <body>, then you can override that CSS setting by creating your own CSS for the <body> tag, for example:

body {
  margin: 0px;
}

The same principle applies to the other major browsers.

The unofficial chart of all browser default style sheets

Here is a nice chart showing the browsers’ default CSS rules

Class 11 – Misc links for today

Saturday, December 12th, 2009

Class 6 – CSS browser compatibility chart

Saturday, October 31st, 2009

The Quirksmode site has a good chart outlining all the majors browsers’ support of standard CSS commands.

The red elements in the chart indicate the features of CSS not supported by the browsers.  This chart makes it easy to see why web developers dislike Microsoft Internet Explorer.

Class 6 – Assignment(s)

Saturday, October 24th, 2009

Please complete all client-side assignments

This week marks the end of covering the client-side technologies, XHTML, CSS, and Javascript.  Next week, we will begin with the server-side technologies, PHP, and MySQL.  So the major assignment for this week is to make sure all your assignments from past weeks are completed, working, and linked from your blog so I can grade them. There will be a general amnesty for late assignments – if you complete them by the end of the week, you will receive a full grade.

PS: Please test the links to your assignments before posting them to your blog.  If the links don’t work, then I can’t see your assignments, which means you get a zero grade for them.  Not a happy conclusion to your hard work.  Also, a screenshot of your assignment is not a substitute for a link to it.  There are several of you who are repeat offenders on both counts – please go through your old posts and make sure all links to past assignments are present and working.

The assignments so far are:

  • Class 1 – Information architecture wireframes
  • Class 2 – Convert simple wireframe to XHTML code
  • Class 3 – Convert three simple wireframes into XHTML & CSS code
  • Class 3 – Convert a wireframe from Class 1 into XHTML & CSS code
  • Class 4 – Convert BlackBook design comp into XHTML & CSS code
  • Class 4 – Convert MTV Videos design comp into XHTML & CSS code (**optional, but recommended)
  • Class 5 – Javascript key-logger
  • Class 5 – Convert e-commerce wireframe into XHTML, CSS, and Javascript code
  • Class 6 – Same e-commerce page as in Class 5′s assignment, but using JQuery
  • Class 6 – Tic-tac-toe game using JQuery (**optional, but not heavily recommended)

Quiz

We will be having a quiz next week on the client-side material, so please make sure you have done all the assignments and gone through all the previous reading material that has been assigned.

Class 4 – Assignment #2

Saturday, October 10th, 2009

For those of you who have completed assignment #1, your next assignment is to go through the same process with this new design comp:

app_screenshot

The image files necessary for this assignment are, as with the previous one, available on the server here.

The global navigation buttons (i.e. “Home”, “Friends’ Videos”, “Featured Videos”) should be done using an unordered list <ul> element, as recommended in the previous assignment.

The only font used on this page is Tahoma.

  • The light blue font color has hexadecimal code, #AEBEE1
  • The dark blue font color is #3B5998
  • The dark gray font color used for the regular text on the page is #333333
  • The light gray font color used for dates is #999999

Some of the background colors used are #F7F7F7 and #D8DFEA.

The light gray borders used between listings in the “Recent Activity” area is #DDDDDD.

The “+” and heart buttons that show up to the right of each video in the “Recent Activity” section should use the sprite rollover technique we discussed in Class 3.  The example of the sprite technique is available here.



Class 4 – Assignment #1

Saturday, October 10th, 2009

The first assignment for this week is to convert the following design comp into valid XHTML and CSS code.  All the necessary images have been pre-cut by your thoroughly competent in-house graphic designer, and are available in the images sub-folder on the server.

app_screenshot

Fonts

The fonts used on the page are Georgia for the serif font, and Arial for the sans-serif font.

Tips

To begin converting any design comp into XHTML and CSS code, I would recommend setting up a basic page with the design comp applied as a background image to the container div, following the background image technique outlined elsewhere.

Then, start thinking about how you would create an outline structure with the proper rows and columns. This usually means thinking in terms of the container div and second-level divs that you can create to generate the basic sections of the page without worrying about the content that goes into each section yet.

If the design comp shows columns of content that sit side-by-side, you may want to look into using the clear/float layout technique, if necessary, which is how you coerce block elements, such as divs, to sit side-by-side.

Avoid using the CSS position or z-index properties.  It is usually not necessary, and is often a source of trouble for inexperienced developers.  Usually, you can position elements properly through a combination of margin and padding, and the float and clear trick.

For this comp, I would start with an outline of the page in the <body> of an XHTML document, something like the following:

<div id="container">
    <div id="main_navigation">
    </div>
    <div id="search_bar">
    </div>
    <div id="search_results">
    </div>
    <div id="footer">
    </div>
</div>

This simple XHTML code has all the major sections of the page broken up into divs.  Now your job is to use CSS to put them into their appropriate positions and sizes.

Once you have the basic layout of the sections done, you can move on to more specifics, and start to think about how some of the parts of the content would be coded in the XHTML.

Global navigation

The global navigation looks like this:

app_screenshot_r2_c4

This is not so different from the global navigation menu example we looked at in class, where we converted an unordered list of elements into a horizontal set of links.

So you might want to do something similar for this assignment.  For example, working off of that example, you might want to set up the XHTML code for this global navigation to be something similar to this:

<div id="global_nav">
   <ul>
       <li class="selected"><a href="#">Recently Opened</a></li>
       <li><a href="#">My Ratings</a></li>
       <li><a href="#">My Friends</a></li>
       <div class="clear"><div>
   </ul>
</div>

Of course, you’ll then have to work on the CSS.  For this example, you will want to use background-images behind each of the list items to give it the red or black background.

Sort options

The sort options allow the user to order the listings shown on the page in a variety of ways.

app_screenshot_r6_c5

You will want to be able to apply the proper colors and styles to the links inside of this section, as well as make the “Recently Opened” link look “active”, i.e. bold.

So you would structure your XHTML in such a way that the whole section is contained within its own <div> tag, and the links are within <a> tags.  The “active” link simply has an “active” class applied to it, which allows you to add special styles to that link in the CSS.

<div id="options">
   Sort Listings by
   <a href="#">Venue Name</a>,
   <a href="#">Top Rated</a>,
   <a href="#" class="active">Recently Opened</a>
</div>

As with the selected element in the global navigation section, we can use a special CSS selector to make the link with class “active” look bolder than the other ones.

Listings

The listings of venues should be a table with one row for each listing.  Each row is divided up into several table data cells.

app_screenshot_r8_c2

As you can see, each table data cell has a few pieces of content.

Here is an example to give you an idea of how you might code the XHTML for one such row.  You do not necessarily have to do your rows exactly like this, but it should at least give you a starting reference point:

<tr >
	<td class="namecell">
		<div class="name">
                    <a href="#" >Travertine</a>
                </div>
		<div class="location">
                    <a href="#" >Nolita</a>
                </div>
	</td>
	<td class="typecell">
		<div class="type">
			<a href="#" >Restaurant</a>
		</div>
		<div class="subtype">
			<a href="#" >Mediterranean</a>
		</div>
	</td>
	<td class="goingcell">
		<div class="going">
			<div class="checkbox_container">
				<input name="going" type="checkbox" class="going_checkbox" >
			</div>
			<label class="going_here">I'm going here</label>
			<div class="clear"></div>
		</div>
	</td>
	<td class="ratingcell">
		<div class="user_rating">
			BB User Rating: 0
		</div>
		<div class="ratebox">
			<a href="#" >Click here to rate!</a>
		</div>
	</td>
</tr>

Pagination

The pagination section towards the bottom of the page is conceptually a list of page numbers.

app_screenshot_r10_c6

And you know that a list should probably be created in code using the <ul> or <ol> tags, as we saw with the global navigation.

Here is an example set of code that could potentially be used to create this pagination section:

<div class="pagination">
	<ul>
		<li class="current"><a href="#">1</a></li>
		<li><a href="#">2</a></li>
		<li><a href="#">3</a></li>
		<li><a href="#">4</a></li>
		<li><a href="#">5</a></li>
		<li><a href="#">6</a></li>
		<li><a href="#">7</a></li>
		<li><a href="#">8</a></li>
		<li><a href="#">9</a></li>
		<li><a href="#">10</a></li>
		<li><a href="#">Next</a></li>
		<li><a href="#">Last</a></li>
	</ul>
</div>

The list item with the class=”current” could be styled differently so that it appears to be “selected with an overline or top border.

Styling the submit button

The submit button in the BlackBook design comp may be a bit confusing.  Here is a tip on how to get your button to look exactly right.

Picture 1

The HTML code is just that for a simple submit button:

<input type="submit" class="blackbooksubmit" value="Submit">

And the corresponding CSS code is:

input.blackbooksubmit {
 background-color:#A30606;
 border:0 none #FFFFFF;
 color:white;
 font-family: Arial,Helvetica,sans-serif;
 cursor:pointer;
 font-size: 11pt;
 font-weight:bold;
 padding:4px 10px 5px;
 text-align:center;
 width:69px;
}

Class 3 – Using container (a.k.a. wrapper) divs

Saturday, October 10th, 2009

Up until now, we have been more-or-less focusing on the grammar and syntax of XHTML and CSS.  Now we will examine some common conventions that web developers use.  These are by no means rules that must be followed, but there is a reason why these techniques are popular and useful, so you should follow them, at least for now.

Put it in a container

In general you want to wrap ALL of the content in the body of your XHTML document inside an outermost div element.  Some people call this outermost div a “wrapper”, and others call it a “container”.  No matter, the idea is the same.  The container div should contain everything else on the page.

For example, the body section of an XHTML document using a container div:

<body>
 <div id="container">
 <!-- all XHTML code for the body of the page goes in here -->
 </div>
</body>

Following this convention gives you more control over how the page is displayed.  For example, some advantages of using container divs:

  • limit the width of the page so it takes up less than the full width of the browser
  • center the entire contents of the page within the browser window
  • easily add margins above and/or below the content of the page
  • apply a background image to just the content area of the page

To sum these advantages up, using a container div allows you to control the contents of a page as a whole, rather than element by element.

Now we will look at some of the CSS code that would allow us to perform each of the above tasks

Limit the width of the page

Setting the width of the page is as simple as setting the width of the container div.  Since all content is inside of the container, all content is restricted to this width:

div#container {
 width: 970px;
}

Center the entire contents of the page

To center the page, you must first give the container a fixed width, as exhibited above.  Otherwise, the container, being a block element, would take up as much width as it can, which in this case would mean the full width of the page.  By reducing the width to a fixed amount, the width of the page is no longer as big as the width of the browser window, so you have room in which to center the content.

Using a container div, centering the page is as simple as adding equal margins to the left and right side of the container.  But how do you know how big to make that margin?  Fortunately, there is a CSS margin setting called “auto” that automatically gives the margins the maximum size available:

div#container {
 width: 970px;
 margin-left: auto;
 margin-right: auto;
}

Easily add margins above and/or below the content of the page

Often, you will also want to remove any top and bottom margins from the container div that the browser may have added by default.  If you recall from the W3Schools margin reference page, the margin property in CSS can take either one, two, or four arguments.  The following code uses the margin property with two arguments to set the top and bottom margins to “0″ and the left and right margins to “auto” in one fell swoop:

div#container {
 width: 970px;
 margin: 0px auto;
}

If you wanted to, you could set the margins for each side of the container individually using the margin setting with four arguments.  The four arguments are in clockwise order: top margin, right margin, bottom margin, and left margin:

div#container {
 width: 970px;
 margin: 0px auto 0px auto;
}

This is equivalent, but much shorter than this code, which does exactly the same thing:

div#container {
 width: 970px;
 margin-top: 0px;
 margin-right: auto;
 margin-bottom: 0px;
 margin-left: auto;
}

Apply a background image to just the content of the page

Applying a background image to the container is as simple as using the CSS background-image property. This will apply only to the background of the container, so if your container is not as wide as the width of the entire browser window, you will see that the background does not take up the full width of the page.

div#container {
 width: 970px;
 background-image: url(../images/background.jpg);
}

Note: the URL used to indicate the image file to use for the background-image must be relative to where the CSS lives.  So, if you have your project set up in a folder called “project_name”, using our standard project folder structure, you will typically have a folder structure that resembles this:

project_name/
project_name/images/
project_name/css/

If the CSS file is inside of the “css” subfolder, and the image is inside of the “images” subfolder, then you will need to use a URL that indicates that the browser should look for the image file one level up from where the CSS file lives, and then inside of the “images” folder.  So if your image file is named “background.jpg”, the URL to use in the CSS file would be:

../images/background.jpg

Class 3 – Homework Assignment

Saturday, October 3rd, 2009

Your homework assignment for this week is to take the wireframes you completed last week and convert them into a real web page using XHTML and CSS code.  Do not worry about the design elements, like graphics, or fonts – simply focus on the layout.  And don’t get caught up in every last detail of your wireframes:  focus on only one or two wireframes, and try to get the layout of the pages as close as you can to what you have in your diagram(s).

It will help to first go through all of the tutorials and examples posted on the class 2 XHTML page of the blog and the class 3 CSS page of the blog up to and including “The secret to layout: float and clear“.  That post is especially useful in understanding how to get elements of your pages to sit where you want them, which is what this assignment is meant to explore.  The posts below that post are not necessary to understand this assignment, but might be interesting to read.

Be sure to post links to your completed assignments on your blog.  Your blog post should include a link to each of your assignments so that I and other students can see them live in the web browser.

Class 3 – Assignment #2

Saturday, October 3rd, 2009
Wireframe for Class 2 Assignment

Wireframe for Class 2 Assignment

Your assignment in class today is to convert this wireframe into XHTML and CSS code.

The XHTML code will involve headings, paragraphs, and images.

Tips

You will undoubtedly want to look up the reference for the <span> tag on the W3Schools site in order to figure out how to change the colors of some words inside the first paragraph.  Using the <span> tag in combination with the CSS techniques of applying styles to individual elements using the XHTML “id” attribute will allow you to style just those words in CSS.

Getting things to sit side-by-side is always an “issue”.  You will find that out when you try to make the image of the mouse sit side-by-side with the paragraph next to it.  And there are generally two ways of approaching the solution:

We will discuss this further in class.

Class 3 – Margins and Padding

Friday, October 2nd, 2009

It is important to become comfortable with the basic CSS properties, “margin” and “padding”.  All “block elements” have both margin and padding properties that affect the way those elements sit in relation to the elements nearby them.

Margin and padding are probably best understood from a diagram.  In the following diagram, we see three block elements (elements that are rectangular in shape), one inside the other.   We are only concerning ourselves with the properties of the yellow element in this example, in order to keep the discussion simple.

Margin and padding of an element

Red arrows indicate the margins of the yellow element, and the green arrows represent the padding of the yellow element

You can see that the margins, represented by red arrows, are the spacing between the outer edge of the yellow element and the inner edge of its parent element (the element that contains it).  Increasing the yellow element’s margins will increase this spacing, decreasing the yellow element’s margins decreases this spacing.

Similarly, the padding, represented by green arrows, is the spacing between the inner edge of the yellow element and the outer edge of the element nested inside of it.  Like the margins, the padding can also be adjusted using CSS.

Margins and padding do not have to be equal on all sides.  View the CSS margin examples and padding examples on the W3Schools site to see how margins and padding can be set individually for each side.

Note that we have only been talking about block elements.  Inline elements also have margin and padding properties, but they behave inconsistently… one you have mastered margin/padding for block elements as outlined here, see this site for a good explanation of how inline elements differ in this regard.