|
CSS1 (The STYLE tag with other elements)
Preview the code. You see, we can add properties to pre-existing HTML tags. In this case, all the text in the body is given the default color red. while every use of the BOLD tag <b> has blue text in it. Of course, we may want to only have some of the bold text have the color blue. like the SPAN tag we can CLASSes to the HTML tags.
Preview it. What happened? this time "some text" is bold but is default text color for the body, and the "other text" is blue and bold. We made a bold tag class by typing B.blueone. We can also force the tags to be context dependent. For instance we may want bold text to be blue only if it's between some paragraph (<p>) tags. Try doing the following:
Preview it. With the above style sheet everytime we use a <b> tag inside a <p> tag the text will not only be bold but blue. To make elements context dependent we simply list the elements on the same line seperated by a space then followed by property values. If we put a comma between the elements then the property values will be used by all of the elements listed. For example do the following:
Now whenever we use the P, B, or I HTML elements, we get blue text. Now that we know the syntax of stylesheets let's explore some more properties and practice using them. Background Properties With stylesheets we can change the background color and image of any element. We will start our discussion by changing the background in the BODY element since it has the most dramatic effect. Just remember that you should try change the background in other elements like H1,P,B,FONT, etc. Okay now let's try the following:
Preview it. Now lets add a background image:
Preview it. Here we simply declare we are using a background image and provide a url by using url(http://www.useractive.com/raindrop.gif); you can use any URL of course.
Preview it. Background-repeat can have three possible values, repeat-x,repeat-y, and no-repeat. By using the Backgound property, here is an even shorter way of doing the same thing:
To Find More CSS Properties: The complete list of CSS properties can be found at the UserActive CSS Reference Since you now know the CSS syntax you should take some time now to go to the reference and explore the properties and experiment with some. Importing Styles with an External CSS File Suppose you've come up with a set of properties (style sheet) that you would like to apply to some or all of the other pages on your web site. From what we know so far we would have to copy and paste the styles into each page. This seems rather like a waste of space and time. Besides if we change our mind about some property we would have to change ALL of the pages one by one. External CSS files save the day for us. We can put all of the styles in to one file then link to it from some or all of our HTML files which will use that file to set the styles. Let's try it. First, clear the current text by selecting Edit -->Erase All Make the following External CSS file. Name it mystyle.css:
Don't bother Previewing this, you won't see anything. Instead, SAVE this file as mystyle.css mystyle.css will be the style sheet for the next HTML page. Select Edit -->Erase All again, and make the following HTML file:
Preview this page. Of course, it's problably not a style you would choose, but we are just learning. ;o) If you are only making one file with this style then it doesn't pay to make an external style sheet, but if you are making many pages then an external styles file will save you much time, especially when you want to make small changes. To make style changes on many pages using this stylesheet you simply change the mystyle.css file and all of the other pages will change too!! Borrowing External CSS From Others' Suppose you really like someone else's style and they have their style definitions in an external CSS file. Here is how you can get a hold of their style code: 1). View the source of their HTML page. 2) Discover the name of the external CSS file. For example, mystyle.css 3) Figure out the full path to the file. For example, http://www.useractive.com/mystyle.css 4) Make a link on a web page directly to the file. 5) Open the web page and click on the link you just made. 6) Save the file. 7) go look at the file you just saved. For example we have a mystyle.css file at http://www.useractive.com/mystyle.css make a link to it like so:
Preview and click on the link. This is the end of this lesson. You should take the time to play with what you've learned before going to the next lesson!! |