|
![]() Build a great website Everything you need to know Webmaster tools included |
|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||
|
CSS Tutorial CSS short for Cascading Style Sheets, with CSS you can save a lot of time by making an external CSS file that applies to all your HTML pages. How is that? Inside the CSS file you define how each tag should look like where ever it is used. For example I want every time I use <H1> and <H2> the text color should be blue, so I write it like a rule in the CSS file like this h1, h2 { color: blue; } And now every HTML file that I include this CSS file in it, and I use <H1> or <H2> it will be in blue. This was just a beginning for you to understand what a CSS is, but there are more details to understand and there more capabilities you can use. We will start with the CSS syntax (rules of writing CSS). This is how a CSS definition looks like selector {attribute: value} /this is the general form The attribute and the value are inside curly braces {} and separated by a colon : . If the value is more than one word we put them between double quotations " ". If we want to define more than one attribute we use semicolon to separate them ; . You can group selectors by separating them with a comma, . Example: h1, h2, p { color : red ; text-align : center } There are two other types of defining how a tag element would look like, these are called Class selector and ID selector. What should we do if we want use <H1> red sometimes, and sometimes blue? That's where the Class selector comes for help. h1.red { color : red } h1.blue { color : blue } (You can write anything after the colon, but it is recommended that you use a meaningful name that makes it easy to remember) And we use them like this <H1 class = "red"> this would be in red </H1> <H1 class = "blue"> this would be in blue </H1> We can also make a general one, which applies to more than one tag. Like this: .red { color : red } / notice the colon at the begging And we use it like this <H1 class = "red"> this would be in red </H1> <P class = "red"> this would be in red </P> <Font class = "red"> this would be in red </Font> The ID selector is used when you need to use a style for more than one attribute. Here is an ID selector #center { text-align : center } And this is how we use it. <p id="green">this text is centered</p> <h1 id="green">this text is centered</h1> And we can also specify the ID selector for a specific tag like this: h1#h1format {text-align: left; color: black} Now remember that these definitions can be put in an external CSS file and the HTML file that wants to use it will link to it using the following statement that goes in the <head> area: <link rel="StyleSheet" href="http://www.buildguide.net/style.css" type="text/css"> Also you can write CSS definitions in the HTML file in the <head> area, between the <style> </style> tags. And of course the definitions written there will be only used by that HTML files. There are some priorities that the browser uses to select which style to use, if the first style is missing then it use the other and so on. The priorities are Inline Style Internal Style (inside the <head>) External CSS file HTML default Here are some attributes and some of their values.
|
|||||||||||||||||||||||||||||||||||