CSS Tutorial
Chapter 2: Basic Web Application design using CSS
There are two basic forms of writing CSS files. They are
1. Internal CSS
- Internal CSS
- External CSS
In internal CSS, your CSS code is tied with the same HTML sheet. It means that you write your style sheet code within the same CSS. In the examples that we saw in the previous chapters, we used internal CSS completely. There are basically two ways to write an internal CSS.
Designing CSS using internal CSS is good enough for beginners who are learning CSS. But to be a professional web developer, this is not a good technique. For instance, if you think of repeating the same <style> tag for every HTML page you write, don't you think it is redundant code and unnecessary replication. And worse still if you want to change the style of a button in a particular web page, you will end up modifying all the HTML pages. Imagine how much effort it would require.
- We can either put our CSS tags within <style type="text/css"></style> tag
- We can embed the CSS within the attribute style of a HTML tag like <h3 style="color:red; text-decoration:none">I am special H3 tag</h3>
So you may ask, that is there any way to write all the common style properties separately and make all the other HTML pages link to that file? The answers is yes.
2. External CSS
You can write all your style sheet related attributes in a separate file which is generally stored with the extension, .css. After doing this, we can link all the HTML pages to this CSS file. Let us see this through an example.
Create a new file called myStyles.css and add the following code to it
Now create a new file called index.html in the same directory as in myStyles.css with the following contentHTML Code:body { background-color: blue; } h2 { color: lightblue; border: thin black; font-family: arial; text-align: center; }
Code:
It should look like this:HTML Code:<html> <head> <link rel="stylesheet" type="text/css" href="myStyle.css" /> </head> <body> <h2>Welcome to CSS tutorials</h2> </body> </html>
In the above code, the line <link rel="stylesheet" type="text/css" href="myStyle.css" /> refers to the style sheet myStyle.css and presents it to the front end. Now any HTML file can refer to myStyle.css and reproduce the same design. Also if you ever need to change any style attribute, all you need to do is edit the myStyle.css and all the files that refer to it will now show you the change.
As you can see, we can set a lot of attributes for each element using CSS. In the above example, we have set the border, color, text alignment for the H2 tag. Other values for text-align can include, left , right also.
So as a web designer, you may now design your web application layout as given below
mainStyle.css
index.html
Folder Contact--> contactStyle.cssFolder Products
--> contact.html
--> contactManagement.html
--> productStyle.cssAs you can see from the structure above, the mainStyle.css can contain all the CSS attributes that are generic to the entire web application. Inside the folder Contact, we have web pages related to contacts. So if we need some special styling to be done in these files, we can override the parent settings or define new settings in a new CSS file, contactStyle.css. Now our HTML page, say contact.html can contain link to both the CSS files as follows
--> productCatalog.html
--> productCart.aspx
Now that we have seen web application design using CSS, we now move on to our third tutorial, CSS Selectors.HTML Code:<head> <link rel="stylesheet" type="text/css" href="mainStyle.css" /> <link rel="stylesheet" type="text/css" href="contactStyle.css" /> </head>
Thanks for sharing this Lop. I am looking forward to seeing some more.
Nice tutorial! I learned some new terminology![]()
Good tutorial, +rep![]()
Nice tutorial mate. You planning on writing anymore after Part III.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
Yes nice one surely.. I am just new to CSS and this much information just awesome stuff for me.. Liked it..
_____________________
corporate awards retin-a
Check out W3Schools Online Web Tutorials if you need any CSS help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks