Web Development
Wednesday, July 15, 2009
I’ll start in 3 mints. If you have any questions you should ask now. Question about the assignment? The ones I saw looked great.
On the blog if you see it there’s an updated post. It’s for the topics today. We’ll go through the advanced Css. There are files up there we’ll go over in detail. Familiarize yourself and we’ll start in 3 minutes.
[Students working.]
I’ll call out attendance so I can learn your names.
Kathryn. Shy? Heidi. Alma. Scott. Jeremy. Mark. Jenna. James. Otis. David. Luca? Carrie Ann. Samantha.
I’ll start. I think there’s one person missing. So I’ll go over all the material from yesterday. And all the CSS layouts. I’ll do a mock up and how you lay out a page. Then will go into the advanced topics on the board. So I step back.
Some are having problems with file management. So I’ll go through it in a rudimentary way.
So first thing you do with web projects is you open up the web browser, obviously, the text editor which is NotePad++ for us. That’s not installed then you open up the WinSCP. We’ve done that before. Just Google NotePad++. Then there’s the download tab up at the top. Download executable. Then click the installer EXE. Then that saves it and you must run it to install. So you should know how to do this. Let me know if you don’t.
I’ll go through the set up of the file systems we use. Where do you want to store the files? On the desktop, or flash drive, etc. You lose track of the files and that’s an issue with everyone. But you need to know where you store the files.
So I choose a place on the hard drive where you can make and save a file. I’ll do this in My Documents. Create a new folder with your name. Or that’s what I’ll do.
Each time you make a file or save a new file it goes in that file. It’s critical for you to know where you put your files. Go into that folder then make a sub folder for every project.
First is called Layout Examples. This is just the name I choose. But you can use what you want. All the files in this example are in THIS folder. Click to get in there. Then I put the files from Text Editor in there.
I make a file index.html. This is Save as … now I must find that folder. Here it’s in My DOcuments. Then I save as, once in the project folder. I save it as index.html.
I’ll start putting HTML code in there. Then I just copy paste from my blog or wherever, since I need the basic structure.
I go to the blog. I scroll to find the simple page I made. It’s the outline of the HTML page. That is what I want. Copy it. Then I paste it into the HTML file.
Save.
Now I have an HTML file that’s a good starting point for all my other work. This file requires the CSS, and we’ll do all design issues I use a tag to indicate this is a style sheet. There’s the link tag. [On screen.]
I put the style sheet file into a folder named Main.css. I know these are all the same.
This links to the subfolder styles. You see in the explorer window I must court a sub folder called styles with a folder called Main.css.
So now file. New folder. Make a folder “styles” and that’s where I save the CSS files. So I create now Main.css.
Student: Half way down where does it apply?
Professor: I didn’t bring that up but it must be in the head. You shouldn’t put it in the body since that’s not good HTML. But the things you do incorrectly sometimes work. The browsers are made to accommodate that.
This is supposed to be in the head is since the way the browser processes the code is it starts from the top to bottom. It looks at the head first before the body so with the style sheet in the head you know the browser will load all the design first. But if it’s in the body it may look jarred. The head loads first in the browser memory. Understand the head loads first. That’s the same with the JavaScript files. We want the behaviors to load appropriately before the body loads.
So we’ll create Main.css. That must be in. The styles folder. And that must be in the same file with the HTML. So in the project folder of layout sample 2 I just need to put the blank CSS file. Text editor, Create new file. Save as. Inside the styles folder. That’s where the code will be — call it Main.css.
That’s the set up of for the project. There’s CSS file and the HTML file and that’s it. That’s the basic set up.
Now I’ll repeat the lay out process from yesterday. Here’s a layout.
Open VISIO. I encourage you to NOT type everything out that I’m typing unless you are very fast.
In here, in visio I start with a general basic diagram. Just for the generic shapes. Drag the rectangle for the page. This is simple. It won’t take long. I’ll make a standard website layout. Here’s the header. I won’t do detail in that. I’ll make a left navigation section. There.
Then I make the footer. Then the content section. That’s for the meain content. Some call this the “C Clam.” [sp?] But that’s not the main word for it. But it’s similar to a “C” shape. This is a template. You can keep the header and footer the same but change what’s in the middle. It’s simple.
Now I’ll code this up.
So I think — I’m working at an agency and I must code this — the first thing I think about are how many Dibs I need. There’s the container Dib. It surrounds everything. Even if you don’t see the box you need boxes around everything.
Second I have the clear header so I need a box for that. Then for the footer and contents too.
Each box translates to “Div bag.” I need the container and the sub-divs.
Student: Can you do a container in a container.
Professor: Sure. You can name it whatever you want too. You’ll see it’s common with all developers. There are conventions you can use but you all look at each other’s code. When you see the container and it’s called container and you steal it you just use the same name.
Now to NotePad++.
I’m going to make a div and call it container. The div is a tag name. ID is an attribute. This is a special attribute I can use to create a style sheet. That’s why I give it an ID. For the DIV with the ID container give it this much padding and etc.
Every div has to close if it opens. Every tag has to close if it opens.
There I have the container. Inside that container has four sub-divs. So let’s make four sub-divs. ID equals header. I’m going to close it for now.
div ID equals left.
div ID equals content.
div ID equals footer.
It helps sometimes, while working on this simple layout, to put the word header inside the header, left inside left, content inside content and footer inside footer.
I will see where the different parts are. I will remove that once I’m done laying out the site.
Go to the style sheet, main.css. This is code you will be recreating for every page you make. It has a box for the container. Just lay out the boxes first for the HTML. You don’t even have to give them the IDs first. Just put divs on the page. We know what they are going to be, approximately.
I’m going to upload this to the server. Let me connect. If you remember you should all have this memorized by now. [server address deleted for security]. Usurae name is [username deleted for security]. Password is [password deleted for security]
Now we are going to get to the WinSCP screen. It’s the first screen we get when we log into the server. I’m going to go through the file system management again. We have to figure out where the files are on our client and our server so we can drag and drop them.
Male Student: I think I went up a few levels.
Teacher: That’s what I’m talking about.
This is not the most intuitive screen. We have to get used to the browser again. When you are lost the easiest thing to do is click either for the client directory or server directory. It shows you the hierarchy.
I remember that I put my files in the My Documents folder, in a sub-document in there. Your files are probably in a D drive.
I’m going to go to my files. This is just on the client side for now. I’m going to double click to get into the folder I created. I’m going to stay here at the level where I can see the folder I made for this project.
I will do the same thing on the server. Click where I am on the server. When you get lost you can always hit the back button, which will turn blue if you navigate away from where you logged in.
To get into where the files live on the web I have to double click to get into [server address deleted for security]. I double click into my folder. Then I find this project in the folder I created. In my case it’s in class 3 and it will live there, it’s not there yet.
I’m now going to drag that whole folder from the client to the server. Now the two will be in sync. Both folders have the same contents.
I drag and drop it into the white space. If you drag and drop on another folder it will put it in that folder, you don’t want that.
Drop into the white space. It will ask you if you really want to copy. Yes you do.
Another problem we will all have at some point, is where do you go in the web browser to see this file? To test it. The first thing that might help is at the top in the blue header section you will see the path. The file structure for where you are on the server. You will see [server address deleted for security]/your name/ any other folder. That’s the starting point to look for the folder on the web browser.
I’m going to go there. [sever address deleted for security]/yourname/class3. I changed the server settings last night so you can see a list of all the files in any folder. I prevented that before because it makes it accessible to hackers. This shows you the inner structure.
I got this URL by looking in WinSCP. Ignoring the first few things in the blue section, but looking after it says [server address deleted for security] and whatever subfolders are after that.
One mistake you may make is double clicking on an HTML in this window. It doesn’t work that way. It will download a copy of the file to your personal computer and open that file. It’s loading onto your local system. Not what we want to do.
You always have to look at what the path is. Then load that yourself, manually, into the browser.
Male Student: When we come in everything has been erased but it’s on the folder? How can I get the code we put in?
Teacher: I have, on the server site, a bunch of stuff for class three that I don’t have the on the client side. I would highlight everything, or do it one at a time, and drag them from the right to the left. I’m downloading from the server to the client. That makes a local copy of all of those files. Then I can edit them from NotePad++.
You should never double click any files in this program. Just don’t do it. It seems like you should be able to but it doesn’t work that way.
We can change the settings and make that ok, but since it will be wiped out everyday we won’t bother.
If I want to open a text file I will first go to NotePad++ then to file open and find that file.
If I want the backgrounds folder I won’t just double click the HTML file. I will go to NotePad++. File. Open. Then I will find wherever that file is, wherever I just downloaded it to.
I always put them in the same subfolder with my name on it so I don’t have to think about where my files are.
I click backgrounds. That’s where I double click to open the file. Don’t ever try to open a file directly from NotePad++. It’s not good for viewing HTML files or the codes that go with it.
You may see me do it when I do shortcut, but I’m very familiar with the program. Don’t do it yourself. Don’t do it at home.
Back to what we were discussing, setting up this diagram [On overhead.] I have the HTML file where I want it. Now I need the styles to look the right way.
How do you lay two things side by side? Things tend to stack on the web in HTML. We are overriding that default behavior and making two boxes stacked side by side.
The first thing to think about in the code is the layout technique we will be using. I recommend we always start with this standard layout for the first week or week and a half. If you want to get fancy later, that’s fine.
I’m going to fix the width of this container div. Everything will rely on this width. I’m going to make it 600 pixels because this screen is small. Generally I do 900.
To make a container that has a width of 600 I have to do that in the style sheet, that’s where the style information goes.
How do I do that? How would I make the computer have 600 pixels wide?
Male Student: In the CSS.
Teacher: What do I write?
Male Student: I’m not sure.
Teacher: Anyone else?
Female Student: div pound container. Open bracket with 600 px. Close bracket.
Teacher: That’s the standard format for applying the style to a particular div with a particular ID.
You saw that a lot yesterday. You will see it again today.
Any questions about how that works? Makes sense? If it doesn’t let me know.
We are going to assume that is 600 pixels wide. If we went and re-uploaded this to the server using example two we have no idea looking at this what is going on. You can’t tell anything from this text we are seeing here [On overhead.]
I have no idea where the divs are. I can see some text but I can’t see how wide they are or their shape. I want to put boarders around every div on the page so I can easily see the structure of every div on the page.
In the CSS I am going to say for every div on the page give it a boarder 1 pixel solid green. That puts a green line around every div on the page.
I now re-upload that to the server. Refresh. Now I can see what we are talking about. This hasn’t changed the structure of the boxes, they were always there but invisible.
That boarder looks about 600 pixels wide. Now I need to set them the way I want them.
Now I want to center it. To center it you do this. In the container you say margin 0 auto. That means the top and bottom margins won’t use a margin, override it with 0 pixels margin.
For the left and right use an automatic margin which will push and automatically make them equal sized.
Imagine that you have equal white space on the left and right.
So I upload it to the server and it’s uploaded.
Another thing you may want to do is to override the settings that exist here — the margin and padding happen inside the boxes or outside. The margin here, is the spacing from the green box to the parent container around it. That’s just the page. The padding is the space in the boxes. It pushes the content away. Margins are external and padding is internal.
So if you give 0 to each the padding and the margin, then there’s none. See the space here? What’s that doing? It shouldn’t be there. It’s just a default that I must override if I don’t want it. It could be either the padding or the margin I can’t tell. I need to re upload the file. So now I’ve overridden it.
But I doesn’t make sense to apply padding here. The margin should be external but it doesn’t need to push away from anything.
I’ll make the note. [On screen.] [Override body tags ... ]
That’s how I leave comments so I remember
the code.
Now I make the header taller and I need these to sit side by side then I’ll add color. First the content.
The div tags stack one over the other. Otherwise why would they be that way / it’s just the default behavior.
That’s part of our job is to get these overridden and to stick side by side. When I say that I am talking about the float properties.
This works like you saw yesterday. The div ID, left. Then I make the style. You float left [On screen.]
Then div id content. That’s left also.
That’s the first rule. Set the float property. That makes them go side by side. The second part of this is that when they are side by side you need a div that pushes stuff in the row under it.
So one more visual change so you can see. I’ll give the container a boarder with a different color. One pixel solid red. This container is red. I override the style to make it red.
Upload to the server. Refresh. You see the container is red. You see the left content and footer is side by side. But the footer should be underneath. Why’s it there? Guesses?
Student: Sizes?
Professor: Maybe. But that’s not the answer I thought of. I didn’t do the necessary part. I have to clear after I’m done with the side by side parts. So in the HTML I add a invisible box after the last thing that’s side by side. I think of these two elements as a row. When you have rows you have columns. So these are the columns in the row. The last thing should be a div.
So I make a div. [On screen.] Just get in that habit with the rows and columns put the invisible column in there. Then the CSS has special properties.
So I make a class with divs. That’s an indicator. I give them the property. Then since I’m setting the border for the divs I want this to be invisible. I must override the border so it won’t show up. It’s invisible.
Re upload to the server. That forces the footer below the two things that are floating.
Student: So when you say both you mean Both sides?
Professor: I’ll bring it up. Let’s do the clear have sides. Here’s the width and height. 20 by 20 pixels. Then the background color. Orange. So it’s an orange box. You’ll see it.
That’s where it lives. But it’s invisible most of the time. But if I said Clear That means both sides. If I just standard deviation clear left let’s see … So there you go. divs use both sides. I’ll make the footer float left too.
Imagine you had a footer with columns stacked so you must flip it.
Well, I wasn’t expecting that. But you can flip them both sides or if you just clear it left and don’t say CLEAR BOTH it doesn’t push the contents down. The just doesn’t stack anything on the left. It ignores the right side. Or if you say “clear right” it forces the stuff below on the right side down. So I just do both sides.
Student: So that’s all it is? It makes the space to the left and right …
Or you can’t go below.
Professor: Sure. That’s all it does.
Now what I need to do is get the sizes here approximate. Quickly. The container is 600 pixels. How big do I want this? In the diagram there are no sizes. This wireframe is not to indicate stuff it’s just a quick and dirty diagram. I won’t analyze the pixel value.
If it’s 600 then I make it 200 it’ll probably look ok.
So the left is 200. [On screen.] That’s the width and the content will be 700 pixels minus 200 pixels. That’s minus the padding which I don’t have.
400 minus the order on all the boxes. This is 600. This is 200 [On screen.] So 400 minus 6 equals … 394. [Content.]
That’s the formula and you can use your eye or just trial by err.
I guess we missed some pixels on the right but no big deal.
So I’ll add 1 or 2 pixels. Let’s say 396 instead.
Student: So you use the X instead of the XPX?
Professor: Oh. I didn’t see that. There. [On screen.]
So I don’t make the heights attached to the divs. You want them to be flexible. It’s ok to scroll up and down so it’s ok if it scrolls up or down. But people don’t like the right to left scroll. You don’t want the width to stretch but it’s ok to let the height stretch down.
Student: What’s the typical width?
Professor: It’s … I’ll go into a way to analyze that so I’ll hold off. There’s no answer you just look at the web. It’s usually under 1000. Any questions? At all about this?
The issues are file management and knowing where your files are. That’s critical. Starting with HTML. And writing the divs. You just put the boxes in the code. Then stetting the container with a fixed width and properties. Then you float what’s side by side. After the rows you have the clear element that uses the line break, etc.
That’s all to layout. It’s not much but it’s complicated to learn. Once you have practice then you can focus on the content and the design. That’s what we’ll talk more about today and getting granular.
Let’s move on.
I’ll get back to the question about the width of pages. If you want to see how wide a website is … let’s look at the NY Times. They have a very wide page. There’s a tool called — I can’t remember. There are many actually.
Research!
So let’s go to Google and look for “FireFox Add Ons ” We talked about how FireFox adds functionality to browsers. You can add stuff to the browsers to measure things on the page. So let’s get that one. I bet there are several. I can’t remember the name. Search for “ruler.”
Draw it out to get the pixel width of an element. I think that’s what we want. Click “measure.” Then the button says “add to FireFox.” This is why FireFox is so nice. Click “install now.” Then you see that you’ve added the measure tool. It requires you to restart to use the tool sometimes. Or it keep south window open and will reopen on the window you used before. Close tabs. Restart.
It kept all the tabs I had. I think there’s a setting in the check box. I can’t remember.
Now we should have this ruler installed. We just have to find where it is. In this case it’s on the bottom left. I’m trying to get it on the screen. There’s a ruler icon. When you click it your cursor will change to cross hairs.
We want to find out how wide the NY Times site is. We need to stretch it. I’m going to click the icon at the bottom left. Now my cursor changed. This will allow me to measure the page manually. It says 973 pixels.
Does anyone have a different number? Something like that.
That’s how wide they made their container div. That’s a pretty wide page. There are not many sites as wide as that. That’s the max.
Let’s try a site like CNN.
Female Student: You always want to measure from boarder to boarder?
Teacher: You want to measure from where you see the content is starting or ending. It’s not always a boarder.
Female Student: Would you measure to CNN.com in the left hand?
Teacher: This site in particular is two parts. The top navigation and the main content. They behave differently. They have a slightly different layout than what we have been doing.
Their main content section is about 985. It’s even wider. That’s good to know. We know it’s ok to make a site 985 wide.
Male Student: [Can't hear/can't understand.]
Teacher: There’s been a steady progression of bigger and bigger widths.
Let’s try another site. Let’s get an idea of the widths around.
Male Student: Jibjab.
Teacher: I’m sorry. This thing is really loud.
I’ve never seen this site before. Is it your birthday today? [Class laughing.]
Male Student: It has all these comic videos. You can send them as cards or just as is.
Teacher: I’m getting 963 or around there. We have a standard that’s going on. High 900 something seems to be ok.
Let’s try one more.
Male Student: Fark. That’s my site.
Teacher: Actually, this seems to be stretching the whole width of the page. This seems to have a minimum width, but no maximum. For this site I would measure the minimum width. I’ll resize until it stops moving and is no longer stretching and shrinking. This is 980. Same range.
Female Student: How do you set a minimum width.
Teacher: There’s a min-width property you can set on CSS.
There are some problems with that kind of layout. The older Internet explorer browsers won’t recognize that.
One thing they may have done on this page is that people used to put an invisible image that has a width of the size that you want. An image will never shrink further. Using an image will force this box to never go smaller.
You get the idea. 960 to about 980 seems to be our range.
Another tool we should install is Fire Bug. We installed it yesterday. Search for Fire Bug. You can also search in the FireFox add-ons page. You can add this to your browser. Find the install button.
This add-on requires the not yet released version of FireFox.
Let’s try again.
Male Student: Just Google it.
Teacher: The first website is what we used the other day. Use the big button.
This link is from the syllabus also in case you lose track and want to look back. This information is there.
You have to allow it to install stuff from this site. Click Allow.
By default there are security settings that FireFox has to prevent other sites from installing programs on your computer.
Let’s try again. After you allow it, it should install.
My computer has an older version of FireFox than your computers have. It’s not working on mine. That’s a shame because I can’t show you what to do with it.
I’ll get to it later. Install it. We will go through it then.
Male Student: There’s a version that works on FireFox 1.5.
Teacher: I’m using FireFox 2. If you go to help, about FireFox it will show you what version you have installed. That’s why mine’s not working.
For some reason my FireFox is downloading 2.0.02. These computers are frozen. Someone must have been downloading FireFox 2 when this thing froze.
We don’t need that now.
Let’s go to advanced CSS. Back to the blog. At the top of the blog is the latest post with the links to the stuff we will be covering.
You might be asking, when using margins and padding, you may wonder how to look at the code for this page? Look at the URL. [server address deleted for security]/myname/class 3.
Go to the server in the WinSCP. Look for my folder from my summer 2009 folder, class 3 folder. Go back to where you first came from when you logged in using the back button. I’m just following these folder names at the top.
Class 3. Margin and padding. That’s the folder with all these files in it. If you drag it to your own folder you will have a replica copy of my file.
That’s how to follow along.
Do you all have that? Should I do it again?
Go into one of those files. NotePad++. File. Open. Find where I downloaded that file. This is hopefully in your folder with your name on it in the margin and padding folder.
I’m going to open the style sheet called marginpadding.css. I want to exhibit a little more what the difference is between margin and padding.
I’m going to change the margin on the left side of this outer red box, the container box. If I set the margin-left to 50 pixels you are going to see the red box shift to the right 50 pixels.
I will re-upload that to the server. The box shifted because I applied a margin to the red box. Margin is the external space between the outside of the box and the thing around it.
If I apply a 50 pixel margin to the yellow box, it will move 50 pixels in to the red box. You are going to see the inner box move in 50 pixels from the edge.
That’s the margin. It’s pushing away from its container.
If I put a padding on the yellow box it will push inside. So let’s apply a padding of 10 pixels to the inner box on all sides. Actually, I’ll make it 30 pixels. That will push on all edges, the content, 30 pixels away from the edge.
We are going to refresh. It pushed away from the inside, 30 pixels away. Padding is the internal spacing. It also made the box bigger. That should be something you are aware of. It may stretch your box.
That’s the only thing I wanted to show. Margin is the external space, padding is the internal space.
Let’s move on. That was a recap of things we have seen before. Now we are going to get into new stuff. Let me just check my blog.
Centering content we saw. This is an example again. We made it obvious by using two different colors. We saw that with the layout we did. That’s there for you to play around with.
A new thing is background image. That’s the first new one. How do you apply a background to a div? Let’s pull that example up.
These are two divs, one green, one red; with two background image settings. One has a tiling background. It keeps repeating as many times as necessary to fill the space. That’s tiling the background.
The second is a non-tiling background. It only shows up once, even if it doesn’t fit the space.
That is done with background-image. In the background folder in styles you see background-image-CSS. These are the two divs we saw. The first has a background image with tiling. The other has background with repeat that indicates to not repeat.
Tiling is the default setting for the browser. If you don’t want to it to tile you have to tell it not to.
Male Student: If it fits into the div it won’t tile?
Teacher: It will still be tiling, but you won’t see it. It would if the image was smaller. If it fits perfectly you just won’t notice that it tiled. It will cut off at the edge of the div.
So it will tile unless you telae it not to using this code. Instead of “no repeat” I’ll change it to “repeat-x ” And that’s repeating horizontally across the div.
So I don’t know if you can tell — there’s horizontal but not vertical tiling. Or you say “repeat-y” and that’s the other way.
I can’t get rid of my NotePad++.
I need to close this down.
There are a few different settings you just saw. The No Dash Repeat. [No-repeat.] I’ll leave the comments for the different settings. Repeat the x the y, etc. So those are the options for background repeat. But I’ll leave up the no repeat to leave it at the original state. You should look at other sites like NY TImes. I can talk about these all I want but you should see them in practice.
And FireBug is useful for analyzing with reverse engineering.
If I right click here on FLash for example — remember the first day? Not expecting really. But you can tell what’s Flash or not when you right click. Or I right click on any image and it says “view image” or “copy image.” That’s an image tag. The IMG tag. It’s a foreground image. It’s used to place the image in the foreground. So I’ll try this logo. That’s an image.
But with the background image you won’t see that. You can tell since it will say “View Background Image.”
Another site. Cute Overload. I’ll right click the logo. That’s not background.
Student: AA.com. The top banner.
Professor: Right click … um, … there. The clouds. There’s no view image or save image. It’s just the background image. It’s huge. So they use that technique in CSS. That’s easier to superimpose things on the background. Then you can just put HTML over that. So there’s a div for the whole thing then inside the div there are the sub sections here [On screen.] These show up on top automatically.
What else? Another site.
NYU.edu. Right click on the logo. That’s a background image I think but it’s not showing up the right way. Then it’s also a link so that interferes.
It’s ok. Just browse around. But you can tell easily. If it says view image it’s using the image tag. Any questions?
Student: When you sit the address or the JPG, if it’s not right on the folder you use can you just tell it to look somewhere else?
Professor: That’s a good question. Back to the AA site.
We established this is a background image. I see view background image when I right click. You can get the address for the image on the Internet too. But if I want to use that. I can do it. So instead of using the image I had on my file systems I can use THEIR image and steal it.
They may not like it! But now I have the AA logo. Do that answer your question? As long as the address is there correctly you can use that image.
One note — some websites do this. They link to other sites and may use one of your images. If you are popular and they want to link to you, they may use an image tag and use your image. That’s bad behavior, since what they are doing, when someone loads it, it makes a hit to the AA server.
But if I had 5 million people on my site, that means AA is getting 5 million requests on their site too. That’s happened to me before and people bring down servers that way.
Student: With the HTML you can adjust the image size? Or with the CSS can I do that?
Professor: No. You should size the images correctly off the bat. Or you use the height and width properties. So you want to use Photoshop to make it the correct size.
A note about the background image property in CSS, the background image property takes one value, that being the URL value. In the parentheses it uses the file name too. It’s an odd syntax but that’s what it takes.
Then the path is relative to where the CSS file is not the HTML file. So since my CSS file lives in the sub flooder styles, there is another sub folder style that’s Images. So I have the one for the style sheets then one for the images.
So to find the image I tell it to go to the root folder then down into the images folder. So the dot dot means “go back.” That’s relative to the CSS not the HTML files, which is the usual route.
So to get to the image files you must go UP a level. That’s all.
Student: … if the HTML is the …
Professor: If you see the text it must be written in HTML.
Any questions? You will see more of this in another example. Not right away though. Creating menus using lists. That’s the next topic.
Remember the tags and lists? The three listed elements? You should see those used to create top navigation links. The most common things you see are the links at the top or on the side. You should use item tags for those. When you see the list on the left vertically they naturally stack themselves. But it’s weird to see them horizontally and it’s not natural behavior. So how do we do that?
Let’s look at this code.
First the HTML. Nothing here is new. The important thing is the unordered list of items. Then I have links listed 1,2,3… but there’s nothing special going on here.
But this is different …
I am removing the margin and the pudding from the body tag. It’s not critical. I centered the container div. I have the standard div.clear. Now I play with the list.
First I remove the bullet point. There are no bullet points here. I removed these through the combination of changing the list style position. You can look at up on … w3schools.com.
So when you see something with a property you can go to the CSS section and I advise you to take these tutorials. Go through this content. I have to fly through this but the stuff I talk about in this class is all listed here.
So we’ll go to the CSS reference section. It’s linked down from this list. It’s a set.
I click the CSS reference. See?
Here in the content area, a bunch of properties you can play with in CSS. They are divided into backgrounds and borders, sizing, fonts, lists. So list style position shows you how to place the bullet point. [List style marker.] I’ve set this to “inside.”
And shows a dictionary of usage of this property. I overrode the default then you see the different vales and how to indicate what to do with the bullet.
This removes the extra space created.
When you have the list item the positioning or spacing is effected by the bullet point. So I’m just removing the space but you don’t have to do that. It’s just a nice way I can save a width.
So just do that when you want to make a horizontal list for navigation.
I’m floating left the list items. It puts them side by side.
seSetting the list style to none moves it so you don’t see it. But this just removes the spacing that’s technically added so this removes the bullet point all together.
Now I’m aligning the text in the center and I’ll set the line height to the height of the list item So this defines the list of text. It’s just a trick. When I set the list height to the line height vertically aligns this text in the box. This is the border, the 50 pixel border. I gave it a line height of 50 but since it’s smaller it aligns it in the space. It’s sort of a hack. It doesn’t make sense really but think that the browser is reserving the height but the font is smaller so it puts it in the middle automatically.
So let’s remove it to see what happens.
Vertical aligning is difficult to do generally.
I took out the line height. I’m not sure what’s going to happen. By default it’s up at the top. If I made that 150 pixels, just to show you what would happen if it wasn’t the same size. The browser is reserving a size for this text, since the font size is only 12 point something.
By setting it the same value I can assure it appears to be in the center of the box.
I will put this next to the height properties so you can see they are always together.
That only works for vertically aligning text. It won’t vertically algin one box inside another box. You just have to play with the tags and margins and find the value that looks right.
We have a set of list items that I have given a specific width and height in the CSS and made them float left so they stack up next to each other. They have a line height the same height as the height property. That’s how you vertically align things.
Questions? Does this make sense?
I know some of you need more time with this. Some of you get it right away. Flag me down if I go way too fast.
We are going to continue down the blog. Read the post from last example. I’m going to pull up the post, static positioning.
By default, the position of any element on the page is static. That’s the default behavior. It appears, more or less, where you put it in the code. The first thing in the code is the red box. In that box is another div with the yellow box. They appear one within the other.
The browser has defaults for a paragraph. It will have some padding around it by default. It may have a margin.
If you don’t change those things, like the position of an element, it’s referred to as static. It’s where the browser will put it by default.
I will use these yellow and red boxes in all examples. I’m not changing anything here. It’s a red box with a yellow box inside of it.
In the next example I’m using relative position. This is the same HTML code, more or less. I added different text. I shifted the yellow box up, so it clips the text a bit.
This is the code for the yellow box that was necessary to do that. I shifted the top property to negative 30. That moved it 30 pixels towards the top of the page.
The red box still has static position. I modified the position property of the yellow box. You can shift things from where they would normally be in the static position.
Is that clear?
Female Student: It’s not all the way on the left because of padding?
Teacher: I may have applied some padding.
It’s the same. Whatever the default was is the same as what we are using. I haven’t changed that. It must have some padding.
Now the next example. Absolute positioning. The red box is again static. I may have centered it. I changed the position property of the yellow box. I made it absolutely positioned. The position is relative to the top left corner of the content area. The pixel coordinates are relative to top left of the content, now where it would normally sit. 50 pixels in, 50 pixels down.
An artifact of that, since the red box is statically positioned and centered, and the yellow box is absolutely positioned, the red box stays where it would normally be when I move it. The yellow box will never move because it’s relative to the top left of the screen. It’s an odd behavior. The yellow box can stretch out of the red box.
This can be used for an effect. You can stick things at certain coordinates on a page like this.
Male Student: Can you move the absolute left 50?
Teacher: You can’t change the left without specifying relative or absolute.
That’s absolute positioning. Stick something in an exact coordinate in the window. It’s important to remember it’s relative to the top left of the window.
Next we are looking at a combination of these two things. Relative positioning on the outer box and absolute positioning on the inner box. You have an unexpected odd behavior. The yellow box is absolutely positioned, like the last example.
Because the red box is relatively positioned this makes the difference. Somehow the browser thinks the absolute position of the inner box is relative to the top left corner of the red box, not of the page. Even though it says absolute it’s absolute to the red box.
I don’t know why that would make sense to the people who designed this, but it’s useful if you want to position something absolutely within a box. We can use this to still have a normal layout, where things move around together, but position something carefully inside that container div.
You won’t see this used as commonly as the other two types. It is something to be aware of that you can use this to your advantage where you want something to be absolutely positioned within another.
With relative positioning you don’t know where the browser, by default, is going to put it. By using absolute positioning for the inner box I can say where it will be.
Questions about this? The positioning stuff.
This is a position property that you can look up in the w3school site later on. This is a good indicator of how to use those things and what they are meant to be used for.
Last thing about positioning would be the Z index. Here I have three boxes. One is on top of the other which is on top of the other. You have X coordinates and Y coordinates on a graph, this is the Z coordinate. The Z index is how far at you is any element.
The red box has the lowest Z index. It’s a number system. This has a Z index of let’s say 0. The yellow is a Z index of 1. The blue is a Z index of 2. It seems the blue is on the yellow which is on the red.
Let me change those around and you will see what I mean.
You can see I set the Z index for the yellow box to be 2. The index for the blue box is 3. That’s why the blue appears to be on top of the yellow one.
If I set the reverse to be true, the yellow to be 3 and the blue to be 2, we get the reverse effect. That will mean the yellow should be visually on top of the blue. Let’s see what happens.
That’s what you get. When you have overlapping elements, which is how I positioned them to be because objects don’t normally overlap, this is the way you would think about which is on top of which. It’s a visual effect. The HTML doesn’t change. The CSS code makes it appear like one thing on top of the other.
Any element can use this. You have to change the position property. It won’t work without relative or absolute positioning.
Just like the top and left properties don’t work unless you use relative or absolute.
Male Student: The 1 would be 100 and .1 would be 10%?
Teacher: Yes.
Male Student: If a div has a background image can you use Z index to put text in front of an image?
Teacher: Yes. I would avoid doing this unless you have a really good reason and can’t do it a different way. In that case I would apply a background image and put the text in front of that.
But yes, it’s possible.
This is related to positioning because you can’t apply Z index without applying relative or absolute positioning first.
If I change this to static let’s see what happens. I changed the blue box to have a static display. It goes to where it would normally sit. Let me take the other box out too so you can see it.
Now they go to where they would normally sit. You don’t have positioning or the Z index. You can’t change the left property, top property or the Z index without changing the positioning.
That’s all for positioning. One more example I have. Using sprites. These are background images. There is a div box with a background image applied. When I mouse over the image it shifts to a different image.
If I right click on one of these it doesn’t say view background image. Let me load the background images manually. That’s what the heart image looks like. That’s the image file. There are three images in the one file. There are three separate versions of the icon.
The other is the same. Three versions of the plus sign.
Why does it show up with one version and not the other? The div is only that big. It hides the rest of the stuff below this. It’s like a window you are putting on the screen. If the background image is too big for the window it hides the rest.
When I mouse over it, I’m taking the background image and shifting it up so you see another version of the image in the window.
Is that confusing to anyone? It’s being shifted back and forth.
The way that works is like everything in CSS,
– well let me open the HTML first. These are the two divs we are looking at. There’s the div then the link or rather it’s a tag for that box. I’m focusing on the fact that there’s a background image though. The CSS looks like … [On screen.] It has a background image for these. That’s the background image property. This whole div looks like I have a div around this. That’s the score you’d see if there were a border. Then this shows a copy that sits to the left. Make sense?
I had the background image not repeating. If you mouse over these, there’s a pseudo class. I repeat the style sheet of the same div but only when you hover over it. You can specify that. That’s for both the divs. These are individual separate solicitors but since they use the same style … this changes the background position so the X coordinate doesn’t change but the Y coordinate changes up a Few pixels. So it shifts the image and exposes the next icon. One of these is 46 pixels high. If you shift it the window shows the next icon down.
Student: Where do the URLs go?
Professor: It’s just one file. This. The graphic designer stacked these three different versions of the icon.
Student: So shifts?
Professor: The background yes.
Student: Or my could all show up?
Professor: Let’s do that. Here’s the div for the first and second icons. Item 1 and 2. You see 20 pixels set for the height. Now I’ll change it to 100. That’s enough to see both I think.
[On screen.]
So you see the background image has all 3. I’m going to put a border around this now. [On screen.]
I’m putting a red border so you can see the sizes. Now each of our many divs are this big. But if I cut it off — 60 pixels for the height. Then it cuts it off somewhere in the middle. So I got the right preparations first so it cut off a certain way.
Now I’ll make it bigger. 150. Then I’ll shift it.
[On screen.]
So I mouse over it you see it shifts up and hides the top. That’s a cool effect. That’s the trick. You use one image. It’s easier in the code and easier for the graphic designer. But it’s better for the browser too. You don’t get three separate hits for each image. It’s better for the small icons. If you have these hover states it’s a very easy and useful technique. So you just design with that idea in mind.
On different page maybe I’ll just use the 3rd. It depends on what you want to do.
Saving the changes.
Ok. That’s it for the examples of what I wanted to cover today. I have a difficult assignment for the rest of the day. But any questions? I’ll press you now to do something more thoroughly than before.
In this folder for class 3. Let’s start with assignment 1 then if you finish do the assignment 2. This is a background image applied to the page. So there’s a container I created. It’s just a big container applied with a background image. I want you to use it as a canvas. This is like you are using a transparency. Use this as a reference then position these where they belong. The images are all in the images folder and I want you to do the HTML and the CSS. But this uses all the techniques you saw today. The different image tags, etc. This just putting it all together in a coherent way. This is the rest of the day and this is most important thing about web development. So just keep going.
This is something I made for BalckBook. I provided a solution but I want you to do the same thing. This is an MTV app so it’s complicated but you are using the same techniques. But start with 1. Think about how you’d code it. Think about the big picture first. How many rows, or columns, and sections.
Here’s the starting point on the server in summer 2003 class 1. There’s an HTML file there called INDEX.HTML. It’s just a container.
Then the style sheet. Main.css removes the padding and margins, etc. and appeals the background to the container so you can develop on top of the image. You can easily develop and place the things over the background so you can get the pixels right. It’s a good technique to superimpose and you can see if it’s in a right place. Like if the search box is down here you see it’s not right.
Understand?
Student: No. The last part about the positioning.
Professor: If I go to the HTML code and I put a logo up here in the top left. I start with the div to get it in the right place. I put the word “logo” in here. Then there’s the div that will have the logo in it. Then I make a style for it. [On screen.]
I give it a width of 300 pixels then 200 pixels for height. Then I give a background color so I see it.
Now, I upload it.
Now I can see it’s too big. So my div does not have the right height and width. I see it’s not right so I change the code. Clear? That’s the point I’m asking you to do. This is the background then you place something over it. So start with the big layout with the rows and columns, etc.
All the images you need are in the Images Folder. These are all the images and there are not many. You can see what they are all for too. Go to the browser assignment 1/images. You click on the images and you see these little images for icons, the logo, and that’s for the logo. But you see all the images you need. They are all there I think.
That’s the navigation items background. Then you put the text over that. But I’ll help you. When you start superimposing you will probably call on me. But let’s get strutted then we’ll do this all day.
If you are stuck please flag me down for help.
Student: Do we create an index file?
Professor: Just use this.
Go to this file. The HTML file. Start there. Then put in divs. I’d put one in the top section. The big one is the container. Then just remember to upload to YOUR folder. Not mine. It happens.
[Students working.]
Student: All the images are here in the folder?
Professor: Yes. If it’s not, let me know.
The background folder is the tiling example I showed you earlier.
[Students working.]
Student: The 3 boxes is that one div?
Professor: Good question. I think it’s one. Or it’s one div around the thing then it’s three smaller ones. But you can do that many ways.
Student: Or in real life they change colors when you mouse over them.
Professor: Don’t do that! Just keep it simple. Make the static page.
[Students working.] .
Ignore what’s appearing in the middle of the image. It’s an artifact that somehow got in the middle of the image. Don’t do that.
[Students working.]
Don’t hesitate to call me if you need any help.
[Students working.]
We can ignore that. [Alarm going off.]
[Students working.]
Its about to 1 o’clock. Take a break from your computers every once in a while. We’ll come back at 2.
[Lunch break]
Is anyone stuck? Need help?
[Students working.]
Anyone else stuck?
Student: I have a question.
[Students working.]
I’m going to make a little presentation about another issue popping up as you go. The difference between two types of contents on the page. Block objects, which are rectangular. Other objects are in line objects, not easily described.
Different elements, like divs, paragraphs, a tags, etc. behave in one of two ways. Divs are block tags. They, by default, will take up as much width as they can on the page. They will have a clear rectangular shape and space between them. They will put a big line break in before and after the code.
In line elements, the other elements, only take up as much width as the stuff inside of them. If there is only this much text in the tag it will only be that big.
They don’t have a clear rectangular shape and they don’t have a built in line break. They will just sit next to anything else you put there.
Let me show you an example of this. If I put some text in next to the div, just some plain text, I didn’t put it in a tag, it sits above the div. I am going to put some below the div too. This is just plain tex with no tags. It’s between the two expand tags.
Let me show you this code.
Text. Div. Text. Span. You can see that the text above the div tag is clearly on a different line. The text below the div is pushed down below the div, but not up from the span tag. The span tag is on the same line. We didn’t indicate anything, but the div isolated itself from the text. The span did not.
That’s the fundamental difference between block elements and in line elements.
This is a list of the common block elements [On overhead.] You come across this on your coding. Divs have built in spacing. Things like spans and A Tags do not. Input tags also don’t automatically go one on top of the other. The text field and button will be right next to each other. The block tags we have to make float. Span tags we don’t have to do that.
Some tags are rectangular in shape and have space above and below them. Other tags just take whatever shape is inside of them and don’t have line breaks before and after them.
When you deal with tags it’s important to know what kind of tag you are dealing with. Here’s the list of blocks and not.
Who asked me about the assignment?
For example, if I were going to try to make this diagram, now that you are adding text, image tag is an in line tag. It will have no problem sitting next to some div or something else. The div will have a problem sitting next to the image. You will have to fault the div. You won’t have to float the image.
The same with this. This is an image of the text SEARCH. The image and the button are all in line types of tags. You don’t need to float them. They don’t mind sitting side by side.
This is an image. That would be some text in a span tag. You would need to float these to get them to sit side by side.
I didn’t want to confuse you with this earlier, but it may help to think about what tag you want to use. That’s the next level of this project.
Male Student: Can you tell the difference between the span tag?
Teacher: If you use P or span? Is that what you asked?
Male Student: Yes.
Teacher: What is this conceptually?
Male Student: Text.
Teacher: What would you call this as far as information architecture? A header. I would try to use an H tag because that’s some kind of heading. A heading indicates what the page is about. I would make this an H1 or H2 tag that I would convert or float to sit next to the other tags.
I would use the best I can the actual heading tag.
Male Student: Can you make it part of the table?
Teacher: You can put a heading in the table. I wouldn’t use tables for layout. I would only use it for tubular cell-like data. It’s fine if you put the other content in a table though.
Did that confuse you more?
Questions?
Male Student: Next to recently opened is an image? Is that part of the header?
Teacher: No. Keep the header. Put the text. The header is in the list of block elements. H1 to H6. If you did use a header you would have to float it to get it to sit side by side.
In the CSS you can change the display property of any element. You can override the behavior of any heading.
Let’s say I had a heading up here. I am going to put some text before and after that heading to show you. By default the heading is a block element. It pushes down from anything and pushes anything after it down.
In the CSS I can change that. H1 tags have a different kind of display. I’m converting a heading from a block element to an in line element. It will now behave totally different. It will behave like a span or A Tag.
Female Student: Why wouldn’t we use the span instead of having to use the div? Are they not interchangeable?
Teacher: That’s why I didn’t want to introduce this too early. It gets tricky.
Let’s bring up the diagram again. That’s a good question.
For example, this has three things side by side. Why would I float them and not just have spans? I want them to be rectangles. I want them to have a rectangular shape, which a span doesn’t have. I’m forcing the rectangular shape.
You have to take those considerations in mind. It becomes an arbitrary choice. You get used to doing it one way or another. You can find a way to make a span have a rectangular shape, but just do it the way you are learning it.
Get used to floating rectangular things as divs side by side.
This brings up another layer of complexity. If it’s too much you can always use a div and float it next to something else. Do what you are comfortable with now, but bare in mind the two fundamental elements.
Questions?
Student: Where will you post the information?
Professor: On the blog. But if you go to the school site. [W3schools.com.] I get the CSS. When you have a question about CSS properties you should go here. There’s the reference page. Look at display properties. It should be in this list. Search for … inline.
It’s in the positioning section. It shows you the different options. They have options I haven’t mentioned. But there’s really just block in inline. Just use the first two. You won’t get bogged down with these.
That’s a big issue with laying out and how to convert the blocks. If you when want the rectangle then use the block. If not, use the float.
So I’ll post an explanation on the blog.
[Students working.]
We have a couple of minutes left. Make sure you save everything and have it backed up on the server.
I think this is a good exercise for a practical application. We will do more of this tomorrow.
We will also most likely hit JavaScript tomorrow.
[End of class.]