+ Reply to Thread
Results 1 to 7 of 7

Thread: CSS Part 2: Common Attributes

  1. #1
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30

    CSS Part 2: Common Attributes

    CSS Tutorial
    Chapter 2: Basic Web Application design using CSS

    There are two basic forms of writing CSS files. They are
    1. Internal CSS
    2. External CSS
    1. Internal 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.
    1. We can either put our CSS tags within <style type="text/css"></style> tag
    2. 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>
    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.

    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

    HTML Code:
    body
    {
        background-color: blue;
    }
    
    h2 {
           color: lightblue;
           border: thin black;
           font-family: arial;
           text-align: center;
    }
    Now create a new file called index.html in the same directory as in myStyles.css with the following content
    Code:
    HTML Code:
    <html>
    <head>
        <link rel="stylesheet" type="text/css" href="myStyle.css" />
    
    </head>
    
    <body>
        <h2>Welcome to CSS tutorials</h2>
    </body>
    </html>
    It should look like this:


    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.css
    --> contact.html
    --> contactManagement.html
    Folder Products
    --> productStyle.css
    --> productCatalog.html
    --> productCart.aspx
    As 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

    HTML Code:
    <head>
        <link rel="stylesheet" type="text/css" href="mainStyle.css" />
        <link rel="stylesheet" type="text/css" href="contactStyle.css" />
    </head>
    Now that we have seen web application design using CSS, we now move on to our third tutorial, CSS Selectors.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: CSS Part 2: Common Attributes

    Thanks for sharing this Lop. I am looking forward to seeing some more.

  4. #3
    Join Date
    Jan 2008
    Posts
    1,725
    Blog Entries
    4
    Rep Power
    29

    Re: CSS Part 2: Common Attributes

    Nice tutorial! I learned some new terminology

  5. #4
    Join Date
    Nov 2006
    Location
    Kosovo
    Posts
    448
    Rep Power
    28

    Re: CSS Part 2: Common Attributes

    Good tutorial, +rep

  6. #5
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: CSS Part 2: Common Attributes

    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!

  7. #6
    tecktalk is offline Programmer
    Join Date
    May 2008
    Posts
    179
    Rep Power
    0

    Re: CSS Part 2: Common Attributes

    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

  8. #7
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: CSS Part 2: Common Attributes

    Check out W3Schools Online Web Tutorials if you need any CSS help.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unable to set values of attributes vis constructor
    By thatsme in forum PHP Development
    Replies: 3
    Last Post: 06-02-2011, 06:20 AM
  2. File Attributes
    By Hunter100 in forum C and C++
    Replies: 5
    Last Post: 08-13-2010, 04:11 PM
  3. LINQ: How to Read XML PARAMETER Attributes
    By SeekAndFind in forum C# Programming
    Replies: 2
    Last Post: 05-06-2010, 09:12 AM
  4. CSS Part 4: Common Attributes
    By Lop in forum Tutorials
    Replies: 4
    Last Post: 02-08-2009, 04:39 AM
  5. .NET attributes are more than decoration
    By hurricanesoftwares in forum C# Programming
    Replies: 3
    Last Post: 08-13-2008, 07:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts