+ Reply to Thread
Results 1 to 5 of 5

Thread: CSS Part 4: 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 4: Common Attributes

    CSS Tutorials
    Chapter 4: CSS Common Attributes

    We will list out common attributes of CSS categorically as follows
    1. Font
    2. Element Formatting
    3. Background
    4. Border
    1. Font
    font-family: Using this attribute, you can specify a list of fonts which are delimited by comma. The CSS engine will browse through the list of fonts you entered and will select the first font that is available. Make sure you specify at least one system font that suits your web page in the end of this list.

    font-size: Using font-size you can specify the size of the font to appear in your HTML element. You can also specify the size in various units. The units can be appended to the end of the size. The units supported are cm, mm, in, pt, pc, px, %. We also have predefined font sizes like medium, large etc.

    font-weight: Using this you can define how the text should appear. Values that you can give for this attribute are normal, bold, bolder, lighter

    Lets see a code sample for Font attributes.
    HTML Code:
    <html>
    <head>
    <style>
    .myFontStyle
    {
    font-family: Comic Sans MS, Times New Roman, Arial;
    font-size: 40px;
    font-weight: bold;
    }
    
    </style>
    <body>
    <h3>I am on my own style</h3>
    <h3 class='myFontStyle'>I am using myFontStyle</h3>
    </body>
    Here is the screenshot:


    As you can see, I am running this script under Linux. But since Comic Sans MS is not something Linux system could have, the CSS engine took the next available font Times New Roman.

    2. Element Formatting
    color: Using this attribute, you can change the color of the text within the specified selector. There are two ways of giving a color value. You can either specify a color literal for standard colors like red, blue, lightblue, violet etc. OR you can specify a hexadecimal color code like #FF2131. The First FF stands for Red components which is set to its full. The second component 21 is for Blue component. And the third component, 31 is for green. So if you say color to be #FFFFFF it is white and #000000 it is black.

    text-decoration: We have used this attribute in our previous examples. It specifies the positioning of a line relative to text. Possible values for this attribute include underline, overline, line-through.

    Lets see a code sample for element formatting
    HTML Code:
    <html>
    <head>
    <style>
    .myFormat
    {
    font-family: Comic Sans MS, Times New Roman, Arial;
    font-size: 40px;
    font-weight: bold;
    color: #FF3311;
    text-decoration: overline;
    }
    
    </style>
    <body>
    <h3>I am on my own style</h3>
    <h3 class='myFormat'>I am using myFontStyle</h3>
    </body>
    </html>
    Here is the output:


    3. Background
    background-color: As you can guess, this sets the background color of the element on which this is applied. We can also specify the background-color to be transparent to show the color beneath the element.

    background-image: Using this attribute, we can specify the image to appear as the background of the element

    background-attachment: Specifies, how the image attached moves according the scroll of screen. This applies in cases where we have image larger than the corresponding container size. Values for this include scroll, background-repeat, repeat

    We have already seen examples for some background attributes like background-color.

    4. Border
    Borders are another common thing that we utilize in HTML pages. The common attributes used for border tag include

    border-style: We can specify the border style using this attribute. Values for this attribute include, border-style: none OR dotted OR solid OR double border-color: This attribute lets us specify the color for the border-style we chose earlier

    Lets see an example for this,
    HTML Code:
    <html>
    <head>
    <style>
    .myBorder
    {
    border-style: dotted;
    border-color: blue;
    }
    
    </style>
    <body>
    <h3>I am on my own style</h3>
    <h3 class='myBorder'>I am using myBorderStyle</h3>
    </body>
    </html>
    Here is the output for this code:


    Now lets move to our final tutorial, Advanced topics in CSS.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

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

    Re: CSS Part 4: Common Attributes

    Code:
    color: #FF3311;
    This can be put more simply like this:

    Code:
    color: #f31;
    Just thought I'd point out.

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

  4. #3
    Jordan Guest

    Re: CSS Part 4: Common Attributes

    Nice work! +rep

    Posted via CodeCall Mobile

  5. #4
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: CSS Part 4: Common Attributes

    nice one .. +rep

  6. #5
    Join Date
    Jul 2006
    Posts
    16,448
    Blog Entries
    74
    Rep Power
    143

    Re: CSS Part 4: Common Attributes

    nice! +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ 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 2: Common Attributes
    By Lop in forum Tutorials
    Replies: 6
    Last Post: 11-30-2008, 01:35 PM
  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