programminghead Logo

HTML Tutorial 3

CSS/Style in HTML

CSS (Cascading Style Sheets) us a style sheet language used for Describing or for changing the HTML Element's default values. You can assume CSSas a Color brush to paint Some Blank Pattern Images. Where HTML tags creates some Blank Pattern of object and CSS will fill Colors and other Details to them.

CSS is not only used to add Colors in HTML objects/Elements, it can be change for Deferent Things like to Change HTML Object's Size, HTML Object's Positions, HTML Object's Opacity,HTML Object's and much more.

CSS Properties:

Before using CSS we have to Know about its Properties, so this will gives us a rough idea, that what we can or what we can't style Using CSS.
Note:we are going to Cover Very little and Impotent Properties Of CSS Here.
CSS Got more Properties then this, Due to This Beginning Tutorial We Can't Cover all the Properties of CSS.

Property Effect
width Change or Assign Width to Selected Element
width : 100px;
height Change or Assign height to Selected Element
height : 100px;
color Add color to the text
color : gray;
background-color Add background color to Selected Elements Background
background-color : red;
font-size Change or Assign Font size to the Text
font-size : 20px;
display can show or hide selected Element
display : none;
float can float text and Elements to giving Positions
float : left;
text-align Align text according to giving positions
text-align : center;
text-decoration decorates by adding underline,bold and other text decorations
text-decoration : underline;
Border change Border size and color
border : 1px solid red;
Margin Adds Margin to selected Element
margin : 4px;

Targeting or Selecting HTML Elements in CSS

HTML
Element
in CSS
HTML Tags <p> this is text </p>
For HTML Tags we only have to write tag name then style properties inside the Curly braces
p { color: red; }
by id name <p id="text" >this is text </p>
for id we have to add # before the ID name
#text { font-family: cursive; }
by class name <p class="para" > this is text </p>
for class we have to add . period or full stop symbol before the Class name
.para { float: right; }
odd tags Add CSS properties to ODD Tags
p:nth-child(odd) { color: red; }
even tags Add CSS properties to EVEN Tags
p:nth-child(even) { background-color: red; }
ODD ID Add CSS properties to ODD IDs
#text:nth-child(odd) { background-color: red; }
EVEN ID Add CSS properties to EVEN IDs
#text:nth-child(even) { background-color: red; }
EVEN Class Add CSS properties to EVEN Classes
.para:nth-child(even) { background-color: red; }
ODD Class Add CSS properties to ODD Classes
.para:nth-child(odd) { background-color: red; }

Writing/using CSS in HTML

As we already know that CSS is a Style Sheet Language, to add or use CSS in HTML we have to Declare/Include CSS inside out HTML Document, For that There is 3 ways to Use/Include CSS inside HTML Element.

Like:
1. In-line CSS,
2. Internal CSS and
3. External CSS.


Internal CSS

Most commonly used to add CSS to HTML Elements. in this way we add CSS internally by Declaring CSS Style tag inside the HEAD tag.
Like :
<head>
     <style> .... </style>
</head>

Internal CSS Example :


<html>
  <head>
    <title>Internal CSS</title>

    <style>
        p
        {
         color : red;
        }	
    </style>

  </head>
  <body>
  <p> 
    Internal CSS Example TEXT
  </p>
  </body>
</html>

Internal CSS Example Explained :

<p> ..... </p>
p (paragraph) tag to write Paragraph inside HTML Document.

<style> .... </style>
style tag for adding Internal CSS to HTML Document.

p { ..... }
targeting/selecting HTML Element (p tag) to add CSS Style to it.

color : red;
CSS Property to changing HTML Element's Color (Text Color).

External CSS :

in this Way of adding CSS to HTML Document is the Best Way to make your Coding Clean, By adding External CSS we only have to Defile the External CSS File's path inside the Head tag and we can use and manage CSS and HTML Documents Separately
but Using External CSS is little risky for Further use.
Because in this Way we are going to ADD a External CSS file to add Style to our HTML Elements. so there are fair chances of loosing External CSS File, misspelling the File name or giving wrong CSS file path
But is can be Useful too. Suppose your website has 10 web-pages and each web-pages use same CSS Properties like (same font-size, same color, same margin) then instead of writing same Style DATA again and Again, you can create a Separate file and just link that CSS file in every Web-pages. This will store time and Reduce the Web-page size

How to Link External CSS :

Before Linking we have to Create our External CSS file.
For creating External CSS file we have to open a new file. (goto file and select new file Option). here write CSS Exactly we write in internal CSS but without the style tag.

Like :
p {
color: red;
}
and save that file with .css extension (Like style.css).

Now To link or include External CSS in HTML we have to write our External CSS file's path inside the <link> tag.
We declare/write the link tag inside the <head> ... </head> tag.

We have to Link our External CSS file Like :
<link rel="stylesheet" type="text/css" href="filename.css"/>

External CSS Example

External CSS Example :


<html>
  <head>
    <title>HTML ParaGraph</title>

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

  </head>
  <body>
  <p> 
    External CSS Example TEXT
  </p>
  </body>
</html>

External CSS file (style.css)


 p{
  color:red;
  background-color:green;
  }

External CSS Example Explained :

<link>
link tag Defines a Link between HTML Document and External Resource like External CSS.

rel="stylesheet"
rel Attribute defines the Relation between Current Document with External File.

type="text/css"
Specify the Media type of the Linked Document.

href="style.css"
(URL) Specify the Location of the Linked Document we be Displayed.

NOTE : here style.css is my filename (style) with Extension (.css). and i'm only writing there two things (filename and Extension) because my HTML Document and my CSS file is in same Directory / in same Folder. But if your CSS file is in Another Path/LOcation then you have to give Full path like :
href="C:/User/Document/style.css"
if you don't know your CSS file's path then Right click on that CSS file and Select Properties and Security
you will see Somthing like
Object name : C:/User/Document/style.css
Copy that path and past inside href="" Double quotes.

Inline CSS :

This way of adding CSS in HTML Element gave us freedom to use/ADD css in particular Line.
For Inline CSS we have to write style="" in the starting tag of that Element where we wont to add CSS.

Like:
<p style=" " > my text </p>
and inside the double quotes (" ") we have to write our style Elements.

like :
<p style="color:red;" >My Text </p>

In-line CSS Example :


<html>
  <head>
    <title>HTML ParaGraph</title>
  </head>
  <body>
  <p style="color:red;"> 
    Inline CSS Example TEXT
  </p>
  </body>
</html>
Comments

minecraft pc download

http://tinyurl.com/y55oestx
11:20 pm

Hi there exceptional blog! Does running a blog such as this take a lot of work? I've virtually no knowledge of programming but I was hoping to start my own blog in the near future. Anyhow, if you have any suggestions or techniques for new blog owners please share. I know this is off topic nevertheless I simply wanted to ask. Kudos!

minecraft free download pc

http://tinyurl.com/y4fa7zjx
03:21 pm

Aw, this was a very nice post. Finding the time and actual effort to generate a really good article_ but what can I say_ I hesitate a lot and don't seem to get nearly anything done.

g

http://tinyurl.com/y4dhd58l
06:16 am

Terrific post however I was wondering if you could write a litte more on this subject? I'd be very grateful if you could elaborate a little bit further. Appreciate it!

g

http://t.co/HjZMjJmKAp
02:08 am

Thanks in support of sharing such a nice idea, piece of writing is pleasant, thats why i have read it completely

minecraft download for free

http://tinyurl.com/y63n48ch
09:07 am

These are really enormous ideas in concerning blogging. You have touched some nice points here. Any way keep up wrinting.

g

http://tinyurl.com/y4jqvo9x
08:28 am

Hello to every body, it's my first pay a visit of this weblog; this web site includes amazing and genuinely fine data in support of readers.

g

http://t.co/HrbQRtcaU5
04:29 am

whoah this blog is great i like reading your posts. Keep up the great work! You recognize, lots of people are hunting round for this information, you could help them greatly.

minecraft free download pc

http://t.co/mNpGUufEwk
09:38 pm

Normally I don't read article on blogs, however I wish to say that this write-up very pressured me to try and do so! Your writing taste has been surprised me. Thank you, very nice post.

download minecraft

http://tinyurl.com/y6z65alf
09:22 am

Hey! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a extraordinary job!

minecraft free download

http://t.co/9iLvUiRiTh
10:35 am

Inspiring story there. What occurred after? Thanks!

minecraft free download

http://t.co/58JlLB2JE6
02:51 am

Hi! Someone in my Myspace group shared this site with us so I came to take a look. I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers! Terrific blog and superb design and style.

gamefly free trial

http://tinyurl.com/y3vetjf2
04:34 pm

Thanks for sharing your thoughts. I really appreciate your efforts and I am waiting for your next write ups thanks once again.

gamefly free trial

http://tinyurl.com/y5z58hcg
04:41 am

Great post. I used to be checking constantly this blog and I am impressed! Very helpful info specially the last part :) I deal with such information much. I used to be seeking this particular info for a very lengthy time. Thanks and good luck.

gamefly

http://tinyurl.com/yy5mzbf9
08:00 am

Thanks for every other informative website. The place else could I get that kind of info written in such a perfect way? I have a challenge that I am simply now running on, and I have been on the glance out for such information.

gamefly free trial

http://t.co/0CB0a94rx6
09:12 am

An interesting discussion is definitely worth comment. I think that you need to write more about this subject matter, it may not be a taboo matter but usually people do not speak about these issues. To the next! Best wishes!!

gamefly

http://t.co/XkGHRnCwMG
06:24 pm

I am regular reader, how are you everybody? This piece of writing posted at this web site is really good.

Write to Us