43 replies
  • WEB DESIGN
  • |
I'm writing this post because of how often I see people asking questions about or saying that they don't know anything about CSS. I know that to the complete novice CSS looks intimidating but really it's a very simple thing to master. There just aren't that many things to get used to. Hopefully this simple explanation of the basics will be enough to get the beginners up and running. This by no means covers everything related to CSS but it is the basic rules and everything else you can Google and understand how to apply the answers you find on Google.

First a word about tags. Tags, with just a couple of exceptions always have an opening tag and a closing tag. For example a paragraph tag is written like so...

<p>
Your paragraph would go in here...
</p>

Note the "/" character in the closing tag. This tells the browser that this is the end of the paragraph tag block. Everything between the p tags is treated and rendered as a paragraph. This general rule of opening and closing tags is pretty much universal with all HTML code/markup. Exceptions would be in the case of certain tags that don't actually have any content such as an <img> tag. These tags contain all their information inside the tag itself. For example...

<img src="/images/MyPic.gif" alt="alt text goes here" />

Notice the closing bracket "/>" contains our closing "/" character. This is what's considered a self closing tag. Maybe at another time we will dissect the different components of the tag.

OK, let's move on to the CSS.

CSS stands for Cascading Style Sheet

It is a way to add styling to your page layout and content. There are basically 3 ways to add your styling to your content.

1.) Internal stylesheet. With this method we add the CSS rules to the header of your document using the <style> tag. This would be done like so...

<head>
<title>Our Page Title</title>

<style type="text/css">
p {font-family:Tahoma;font-size:14px;color:#000000;line-height:16px;letter-spacing:1px;}
h1 {font-family:Arial;font-size:36px;color:Blue;line-height:38px;letter-spacing:1px;}
</style>

</head>


This method makes our style rule available to the document in which the style is placed. In other words if you want this style applied to other documents then this code has to be placed in the head of each document. Note also that the way our style is written it will be applied to every <p> tag and every <h1> tag in our document.

2.) External stylesheet This is probably the most useful method because it separates the CSS from the document and allows you to keep all of the CSS for your entire site in one place or file. To do this we create a file with a .css extension, something like "site.css" Then we link this file to our HTML document by placing the link in the head section of the HTML document. We write our link like so...



<link href="site.css"rel="stylesheet"type="text/css"/>

And it would go in the head of our HTML document like so...

<head>
<title>Our Page Title</title>
<link href="site.css"rel="stylesheet"type="text/css"/>
</head>

Notice that our link tag is a self closing tag with the "/" character at the end of the tag. Also notice that our tag has three attributes, "href", "rel", and "type". "href" is short for Hypertext REFerence and is the URL of the thing we are linking to. In our example above it is our CSS file name "site.css". In this example our css file is in the same folder as our web page so there is no file path used i.e. "folderName/site.css" Next is "rel" short for relationship which is a stylesheet. And last is "type" or MIME Type, in this case "text/css" All three of these elements must be in your link tag.

OK so that is a properly formed link tag and it allows our web page to talk to our CSS file. It also means that our web page will now look first to this file for any styling to be applied when the page is rendered. The only part of this tag you will ever have to edit is the "href" attribute. It must have the name/path to your .css file. Your page must be able to find your CSS file.

Defining styles in an external stylesheet we will use "class"s and "ID"s. A class is denoted using a "." so a class name would be written like so...


.MyClass
{
}

And an ID is denoted using the "#" character like so...

#MyID
{
}

An ID can only be used once on any page where as a class can be used over and over.

3.) Inline styles. This method might easily have been listed first but I chose to list it last because it has another use besides just applying a style to an element on our page. But first to the method. An inline style can be defined within a page element such as a <p> tag or a< h1> tag or any number of other tags. We would do this like so...

<p style="font-family:Tahoma; font-size:14px;color:Black; text-align:left;">
Our paragraph text goes in here...
</p>

This method means applying a style individually to each and every element of our page. This can be a real nightmare especially when our site grows to any size.

There is however another very useful thing we can do with this method. Let's say we have an h1 style defined in our css file like so...

h1
{
font-family:Tahoma;
font-size:28px;
color:Blue;
}

Now let's say we have one particular h1 tag that we want to be different than every other h1 tag on our site. We can use an inline style on the individual tag and it will override the style that is defined in our stylesheet. Styles applied at the element level are applied before styles that are defined in a stylesheet. So we could make a change to our h1 tag like so...

<h1 style="font-size:50px;">
Our altered heading text
</h1>

This will give us an h1 heading that gets all of its styling from our css file except the font-size. The font-size will be applied from the inline style. So this h1 heading will be a blue Tahoma font 50px high instead of 28px high.


Similarities and Differences


In all three of our methods you will notice that styles are defined using the same syntax, a name and a value i.e. name: value; In each pair the name is separated from the value by a colon ":" and each name/value pair is closed with a semicolon ";" This syntax is common across each method whether it's an inline style or an external stylesheet.

What is different is the way our styles are packaged. For an inline style we use the "style" attribute which for inline styles is written like so...

style="name:value;"

This style of notation is used within a tag like so...

<p style="name:value;">
Our paragraph text goes in here...
</p>

You will notice that the style is inside the opening <> brackets and the style="" attribute houses our name/pair elements. But the name:value;always uses the same syntax.

Next, in an internal stylesheet we still see the same name:value; syntax but we wrap it in "<style>" tags like so...

<style type="text/css">
p {font-family:Tahoma;font-size:14px;color:#000000;line-height:16px;letter-spacing:1px;}
h1 {font-family:Arial;font-size:36px;color:Blue;line-height:38px;letter-spacing:1px;}
</style>


No doubt you see some differences here. In our opening style tag we have the "type" attribute that tells our HTML document that the MIME Type is "text/css" and also you will notice that our page elements that we are defining styles for are declared here, i.e. "p { }" and "h1 { }" You will also notice that neither of these is preceded by a "." (class) or a "#" (ID). This is because these are native elements therefore they are denoted simply "p" or "h1" or whatever the element is.


Lastly we come to the external stylesheet. Again we see thename:value; syntax but this time we drop the style declaration altogether. For this method we simply declared the name of our class or ID and then list our style attributes wrapped in curly braces "{ }" like so...


p
{
font-family:Tahoma;
font-size:14px;
color:#252525;
text-indent:12px;
text-align:left;
line-height:20px;
letter-spacing:1px;
width:600px;
max-width:650px;
}



h1
{
font-family:Tahoma;
font-size:28px;
color:Blue;
}

In the above example I have defined styles directly for the <p> tags and the <h1> tags. A better way might be to define a class like so...

.leftAlignedBlue
{
font-family:Tahoma;
font-size:14px;
color:#005bb7;
text-indent:12px;
text-align:left;
line-height:18px;
letter-spacing:1px;
width:600px;
max-width:650px;
}

By using this method when I want to apply this in my HTML document I would simply write my <p> tag like so...

<p class="leftAlignedBlue">
The paragraph text goes here...
</p>

You see in my opening <P> tag I call my class "leftAlignedBlue" and the style that is defined in my CSS file is applied to my paragraph text. Doing it this way I can have several styles defined and apply them whenever or wherever I like.
#beginner #css
  • {{ DiscussionBoard.errors[3917843].message }}
    • Profile picture of the author ronc0011
      Originally Posted by FendyAziz View Post

      Very complicated to understand
      What part are you having difficulty understanding?
      {{ DiscussionBoard.errors[3920938].message }}
  • Profile picture of the author em20346
    Banned
    video tutorial
    youtube /watch?v=6HK81Z7g-mA
    {{ DiscussionBoard.errors[3917942].message }}
  • Profile picture of the author riz92
    thank!verry useful for a beginner like me!
    Signature
    I Want to sell my domain for $500 - Smartwordpress.com
    {{ DiscussionBoard.errors[3919068].message }}
  • Profile picture of the author branabothu
    you can do the same style in other way with in css.

    Suppose you have content div

    #contentdiv{
    write the properties here
    }

    if you need to give the diffrent styles of css with in this content div you can do as below

    #contentdiv p{

    }
    {{ DiscussionBoard.errors[3943681].message }}
  • Profile picture of the author branabothu
    if you need to understand about the css check the below site


    if you are interested i can make you familiar in all the properties and with in days you can be well know person of css

    Regards,
    Bikshama Reddy.R
    {{ DiscussionBoard.errors[3943693].message }}
  • Profile picture of the author tonymontana007
    thanks for this thread...it helped alot.
    {{ DiscussionBoard.errors[3949579].message }}
  • Profile picture of the author seomelbourne
    CSS always plays a vital role in web design! CSS is easy to learn and understand...! Thank! Very useful for a beginner like me..!
    {{ DiscussionBoard.errors[4008124].message }}
  • Profile picture of the author Istvan Horvath
    Exceptions would be in the case of certain tags that don't actually have any content such as an <img> tag. These tags contain all their information inside the tag itself. For example...

    <img src="/images/MyPic.gif" alt="alt text goes here" />
    The example above is valid code ONLY in XHTML - you need to "close" the tags in this way only in XHTML.

    For 'plain' HTML the correct code is:
    Code:
    <img src="/images/MyPic.gif" alt="alt text goes here">
    Signature

    {{ DiscussionBoard.errors[4017240].message }}
  • Thanks for this post. =)
    {{ DiscussionBoard.errors[4017317].message }}
  • Profile picture of the author ashleex
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[4020891].message }}
    • Profile picture of the author AndrewS78
      I always hated CCS.. it is just boring, but you've explained well here. Will read all the post later
      {{ DiscussionBoard.errors[4020951].message }}
      • Profile picture of the author ronc0011
        Well, like I pointed out in the post it's only a starting point and I hope I gave enough foundational information to at least help the newbe get their bearings. There is a lot of nuances to CSS but once you understand the basics of how it works you should be able to Google anything else you want to accomplish. It really is one of those things where you are always learning something new.
        {{ DiscussionBoard.errors[4021134].message }}
  • Profile picture of the author summerfranken
    [DELETED]
    {{ DiscussionBoard.errors[4030897].message }}
    • Profile picture of the author Johnletton
      Originally Posted by summerfranken View Post

      Complicated but useful according the initial point of view. Thank you very much.


      Yes it is complicated for a newbie like me but not bad tutorial although lengthy.
      {{ DiscussionBoard.errors[4038353].message }}
    • Profile picture of the author Johnletton
      Originally Posted by summerfranken View Post

      Complicated but useful according the initial point of view. Thank you very much.


      Yes it is complicated for a newbie like me but not bad tutorial although lengthy.
      {{ DiscussionBoard.errors[4038408].message }}
  • Profile picture of the author samstephan9
    Thanks it's really useful and all beginners including me.
    {{ DiscussionBoard.errors[4030993].message }}
  • Profile picture of the author olakh
    Good info for starting CSS.But you could also add youtube video regarding this concept.
    {{ DiscussionBoard.errors[4031023].message }}
  • Profile picture of the author addison.agnote
    Complicated to understand at first, but i'll tell you read this over and over and you will learn from this.
    {{ DiscussionBoard.errors[4037518].message }}
  • Profile picture of the author rnsinformatic
    Hi Ronc0011,
    Thanks for this useful info. I have confusion between class and id. Now I got and will save this link for future reference.
    #myclass
    {
    }
    .myid
    {
    }

    we can use it as...
    <p id="myclass">Content</p>
    <p class="myid">Content</p>

    thanks again to clear these things.
    {{ DiscussionBoard.errors[4059052].message }}
  • Profile picture of the author uwapik
    thank for sharing, iam very beginer...
    {{ DiscussionBoard.errors[4059375].message }}
  • Profile picture of the author armandobloom
    nice thread...thnx for sharing...
    {{ DiscussionBoard.errors[4060901].message }}
  • Profile picture of the author Logo Design
    Thank You for sharing
    {{ DiscussionBoard.errors[4211050].message }}
  • Profile picture of the author 1babywarrior
    nice, i always loved css, especially since it was the easiest language for me to learn, good thread.
    {{ DiscussionBoard.errors[4214774].message }}
  • Profile picture of the author arlenelema
    CSS is a advanced scripting language so to learn it first one should make the concept clear of HTML.HTML is a basic language for web designing.
    {{ DiscussionBoard.errors[4218146].message }}
  • Profile picture of the author pravintprasath
    What is CSS?

    • CSS stands for Cascading Style Sheets
    • Styles define how to display HTML elements
    • Styles were added to HTML 4.0 to solve a problem
    • External Style Sheets can save a lot of work
    • External Style Sheets are stored in CSS files
    Cegonsoft Dot net training
    {{ DiscussionBoard.errors[4219166].message }}
  • Profile picture of the author mahesh2010
    Hello ,

    Nice post and it is very useful to beginners and there more other than this in css as it can be fully made as object oriented they can override and can be inherited etc this will be quite interesting when we move higher to css and styling it using javascript or jQuery
    {{ DiscussionBoard.errors[4219642].message }}
  • Profile picture of the author wcardinal
    A couple of things I would amend and expand upon...

    1. you can use multiple classes on one element, but only one ID. For example:

    PHP Code:
    <class="center blue"
    PHP Code:
    <h2 id="main-heading" class="blue section"
    2. With this in mind: nstead of using a color or design name as a class, use a class name that describes the function of the class instead. It is easier to universally change the class thru CSS than having to edit you HTML later.

    For example, instead of

    PHP Code:
    <class="center blue"
    let's use...

    PHP Code:
    <class="important callout"
    ...then style the class .important with the color:blue. If you want to change "important" elements later to color:red, you can easily change it once in your CSS.

    Style .callout with text-align:center and later it is easier to add a border or background to the class "callout" if you want to change how it is handled..

    This is what is called "semantic CSS". You are naming the classes with the function they perform, rather than the style you are applying.
    .
    .
    .
    {{ DiscussionBoard.errors[4219832].message }}
  • Profile picture of the author CaliChristian
    Good stuff mate!

    I would also try W3Schools Online Web Tutorials if you're a noob!
    Signature
    Christian Credit Counselors is a non-profit organization that has been credit counseling for 20 years and our credit counselors have helped over 200,000 individuals and families get out of debt in less than 4 years.
    {{ DiscussionBoard.errors[4222913].message }}
  • Profile picture of the author bintos
    Nice tips Thanks for sharing and i think it can be very useful for beginners if they learn here and ask question.
    {{ DiscussionBoard.errors[4226297].message }}
  • Profile picture of the author Sohel Parvez
    Sir,
    can you share with us how to create Drop Down Menu by CSS.
    Many Thanks
    {{ DiscussionBoard.errors[4296220].message }}
  • Profile picture of the author nancyviliums
    CSS is a cascading style sheet.CSS if an advanced of HTML.The tag in it is not predefined and one can easily get along with it is he just study on the internet about it.
    {{ DiscussionBoard.errors[4320753].message }}
  • Profile picture of the author Nexstair
    It is my luck that i got a chance to read all.You defined things in very elegant way ! i really like it and understood at first attempt.Do you have a website/blog where i can learn advanced CSS?
    {{ DiscussionBoard.errors[4323125].message }}
  • Profile picture of the author mickdonald37
    CSS Beginner Tutorial accepts that we know as much about CSS as we do about the accumulative effects of sea spirt discharge on the brain chemistry of Germanic ammonites. The purpose of this guide is to teach the bare essentials exactly enough to get commenced.
    {{ DiscussionBoard.errors[4451064].message }}
  • Profile picture of the author Justin Says
    Great information! Thanks a lot. I was trying to express something to someone that didn't know anything about CSS and this definitely helped (they aren't a warrior member).
    Signature

    My name is Justin Lewis. My digital marketing company has been in business for over 10 years with multiple six-figure years. We do provide a premium web design service.

    {{ DiscussionBoard.errors[4451274].message }}
  • Profile picture of the author Ben_R
    for teh beginner - i recommend css teh missing manual - from amazon - amazing book - also teh basic idea css is for styling how html and other code looks - is an important one -

    everything you see is done with css -html teh basic layout and php for making it go round the world with th server - its very easy once the penny drops on fundamentals -

    gd luck
    {{ DiscussionBoard.errors[4452238].message }}
  • Profile picture of the author jopex
    I also recommend W3Schools, it's a great free resource. I learned a lot of stuff from there.
    {{ DiscussionBoard.errors[4452367].message }}
  • Profile picture of the author leppozdrav
    Nice post and it is very useful to beginners and there more other than this in css as it can be fully made as object oriented they can override and can be inherited etc this will be quite interesting when we move higher to css and styling it using javascript or jQuery
    {{ DiscussionBoard.errors[4463828].message }}
  • Profile picture of the author SteveRocks
    very very helpful guide,,,,,,,I read it completely, tried to memorize and kept and back up..................Thank you very very much.....In fact CSS always seems so dangerous that I never tried to read a single line and what I always did is copy pasting but today my last hour gave me such knowledge that i feel flying ..............lalalaaaaallaaaa...
    Thanks Thanks Thanks.....
    {{ DiscussionBoard.errors[4464901].message }}
  • Profile picture of the author androidmark
    Great info,very useful for a beginner like me!
    {{ DiscussionBoard.errors[4469374].message }}
  • Profile picture of the author munirz
    Ok i think this helped me a lot even its complicated.
    Because in coding i did like prefer to learn from video than words and this is what
    a newbie like me thought.
    {{ DiscussionBoard.errors[4471422].message }}
  • Profile picture of the author munirz
    Ok i think this helped me a lot even its complicated.
    Because in coding i did like prefer to learn from video than words and this is what
    a newbie like me thought.
    {{ DiscussionBoard.errors[4471426].message }}
  • Profile picture of the author RFrancis
    Thanks for helping me understand some basic stuff
    {{ DiscussionBoard.errors[4474094].message }}
    • Profile picture of the author briansmith12
      This seems to be a great tutorial, I'd wish I had something like this when I started. This tutorial was incredibly helpful for CSS beginner. Thanks for making this awesome tutorial.
      {{ DiscussionBoard.errors[4476321].message }}
      • Profile picture of the author frank2011
        Banned
        [DELETED]
        {{ DiscussionBoard.errors[5023563].message }}
        • Profile picture of the author ronc0011
          Well i just can't tell you guyS how gratifying is to know so many of you have been able to benefit from this also a note for munirz i think i will be doing some videos on coding AND css using Microsoft's visual web developer. I.e. Visual Studio. I just completed several videos on using Corldraw for creating web graphics. As a rule i will use Corel to create the basic graphic and then save it as a psd file and then do all my finish work in Photoshop. But for a lot of the initial design stuff I like Corel simply because its just sooo much faster than illustrator.
          {{ DiscussionBoard.errors[5024555].message }}

Trending Topics