SlideShare a Scribd company logo
Using the                                   CSS
Prepared by: Sanjay Raval | http://www.usableweb.in/
What is CSS?
CSS is a language that’s used to define the formatting applied to a Website, including
colors, background images, typefaces (fonts), margins, and indentation.

Let’s look at a basic example to see how this is done.


  <!DOCTYPE html>
  <html>
  <head>
  <title>A Simple Page</title>
  <style type="text/css">
  h1, h2 {
  font-family: sans-serif; color: #3366CC;
  }
  </style>
  </head>
  <body>
  <h1>First Title</h1><p>…</p>
  <h2>Second Title</h2><p>…</p>
  <h2>Third Title</h2><p>…</p>
  </body>
  </html>
Using CSS in HTML
lnline Styles
The simplest method of adding CSS styles to your web pages is to use inline styles.
An inline style is applied via the style attribute, like this:


     <p style="font-family: sans-serif; color: #3366CC;">
     Amazingly few discotheques provide jukeboxes.
     </p>




Inline styles have two major disadvantages:
1)     They can’t be reused. For example, if we wanted to apply the style above to another p element,
       we would have to type it out again in that element’s style attribute.
2)     Additionally, inline styles are located alongside the page’s markup, making the code difficult to
       read and maintain.
Using CSS in HTML
Embedded or Internal Styles
In this approach, you can declare any number of CSS styles by placing them between the opening
and closing <style> tags, as follows:


   <style type="text/css">
   CSS Styles here
   </style>



While it’s nice and simple, the <style>tag has one major disadvantage: if you want to use a
particular set of styles throughout your site, you’ll have to repeat those style definitions within
the style element at the top of every one of your site’s pages.
Using CSS in HTML
External Style Sheets
An external style sheet is a file (usually given a .css filename) that contains a web site’s CSS
styles, keeping them separate from any one web page. Multiple pages can link to the same .css
file, and any changes you make to the style definitions in that file will affect all the pages that
link to it.


To link a document to an external style sheet (say, styles.css), we simply place a link element in
the document’s header:

   <link rel="stylesheet" type="text/css" href="styles.css" />
CSS Selectors
Every CSS style definition has two components:
     A list of one or more selectors, separated by commas, define the element or elements to which the
      style will be applied.
     The declaration block specifies what the style actually does.
CSS Selectors
Type Selectors – Tag Selector
By naming a particular HTML element, you can apply a style rule to every occurrence of that
element in the document.

For example, the following style rule might be used to set the default font for a web site:

  p, td, th, div, dl, ul, ol {
      font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
      font-size: 1em;
      color: #000000;
  }
CSS Selectors
Class Selectors
CSS classes comes in when you want to assign different styles to identical elements that occur in
different places within your document.

Consider the following style, which turns all the paragraph text on a page blue:


   p { color: #0000FF; }


Great! But what would happen if you had a sidebar on your page with a blue background? You
wouldn’t want the text in the sidebar to display in blue as well—then it would be invisible. What
you need to do is define a class for your sidebar text, then assign a CSS style to that class.

To create a paragraph of the sidebarclass, first add a classattribute to the opening tag:


   <p class="sidebar">
   This text will be white, as specified by the CSS style definition
        below.
   </p>
CSS Selectors
Class Selectors
Now we can write the style for this class:


   p { color: #0000FF; }
   .sidebar { color: #FFFFFF; }



This second rule uses a class selector to indicate that the style should be applied to any element
of the sidebar class. The period indicates that we’re naming a class—not an HTML element.
CSS Selectors
ID Selectors
In contrast with class selectors, ID selectors are used to select one particular element, rather
than a group of elements. To use an ID selector, first add an id attribute to the element you wish
to style. It’s important that the ID is unique within the document:


   <p id="tagline">This paragraph is uniquely identified by the ID
       "tagline".</p>


To reference this element by its ID selector, we precede the id with a hash (#). For example, the
following rule will make the above paragraph white:


   #tagline { color: #FFFFFF; }


ID selectors can be used in combination with the other selector types.

         #tagline .new {
                      font-weight: bold;
                      color: #FFFFFF;
         }
CSS Selectors
Descendant or Compound Selectors
A descendant selector will select all the descendants of an element.

         p { color: #0000FF; }
         .sidebar p { color: #FFFFFF; }



         <div class="sidebar">
                      <p>This paragraph will be displayed in white.</p>
                      <p>So will this one.</p>
         </div>



In this case, because our page contains a div element that has a class of sidebar, the descendant
selector .sidebar p refers to all p elements inside that div.
CSS Selectors
Child Selectors
A descendant selector will select all the descendants of an element, a child selector only targets
the element’s immediate descendants, or “children.”

Consider the following markup:

         <div class="sidebar">
             <p>This paragraph will be displayed in white.</p>
             <p>So will this one.</p>
             <div class="tagline">
                      <p>If we use a descendant selector, this will be
             white too.        But if we use a child selector, it will be
             blue.</p>
             </div>
         </div>
CSS Selectors
Child Selectors
In this example, the descendant selector we saw in the previous section would match the
paragraphs that are nested directly within div.sidebar as well as those inside div.tagline. If you
didn’t want this behavior, and you only wanted to style those paragraphs that were direct
descendants of div.sidebar, you’d use a child selector.

A child selector uses the > character to specify a direct descendant.

Here’s the new CSS, which turns only those paragraphs directly inside .sidebar (but not those
within .tagline) white:


         p { color: #0000FF; }
         .sidebar>p { color: #FFFFFF; }




   Note: Unfortunately, Internet Explorer 6 doesn’t support the child selector.
Most Common

CSS Mistakes
ID vs. Class What
An ID refers to a unique instance in a document, or something that will only appear once on a
page. For example, common uses of IDs are containing elements such as page wrappers,
headers, and footers. On the other hand, a CLASS may be used multiple times within a document,
on multiple elements. A good use of classes would be the style definitions for links, or other types
of text that might be repeated in different areas on a page.


In a style sheet, an ID is preceded by a hash mark (#), and might look like the following:


         #header { height:50px; }
         #footer { height:50px; }
         #sidebar { width:200px; float:left; }
         #contents { width:600px; }
ID vs. Class What
Classes are preceded by a dot (.). An example is given below.

         .error {
         font-weight:bold;
         color:#C00;
         }
         .btn{
         background:#98A520;
         font-weight:bold;
         font-size:90%;
         height:24px;
         color:#fff;
         }
Redundant Units for Zero Values
The following code doesn't need the unit specified if the value is zero.

   padding:0px 0px 5px 0px;


It can be written instead like this:


   padding:0 0 5px 0;


Don't waste bytes by adding units such as px, pt, em, etc, when the value is zero. The only
reason to do so is when you want to change the value quickly later on. Otherwise declaring the
unit is meaningless. Zero pixels is the same as zero points.
Avoid Repetition
We should avoid using several lines when just one line will do.
For example, when setting borders, some people set each side separately:

         border-top:1px solid #00f;
         border-right:1px solid #00f;
         border-bottom:1px solid #00f;
         border-left:1px solid #00f;



But why? When each border is the same! Instead it can be like:


   border:1px solid #00f;
Excess Whitespace
Usually we have tendency to include whitespace in the code to make it readable. It'll only make
the stylesheet bigger, meaning the bandwidth usage will be higher.


Of course it's wise to leave some space in to keep it readable.
Grouping Identical Styles together
So when we want a same style to a couple of elements. It is good to group them together and
define the style instead of defining the style for each element separately.

         h1, p, #footer, .intro {
         font-family:Arial,Helvetica,sans-serif;
         }



It will also make updating the style much easier.
Margin vs. Padding
As margins and paddings are generally be used interchangeably, it is important to know the
difference. It will give you greater control over your layouts. Margin refers to the space around
the element, outside of the border. Padding refers to the space inside of the element, within the
border.

Example: No Padding, 10px Margin

          p {
          border: 1px solid #0066cc;
          margin:10px;
          padding:0;
          }




Result:
Margin vs. Padding
Example: No Margin, 10px Padding

          p {
          border: 1px solid #0066cc;
          padding:10px;
          margin:0;
          }




Result:

More Related Content

What's hot

How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
CSS
CSS CSS
CSS
Sunil OS
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
Michael Jhon
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
Nitin Bhide
 
css.ppt
css.pptcss.ppt
css.ppt
bhasula
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
Hatem Mahmoud
 
What is CSS?
What is CSS?What is CSS?
What is CSS?
HalaiHansaika
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
KushagraChadha1
 
Css
CssCss
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
Ardee Aram
 
Class 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & IdsClass 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & Ids
Erika Tarte
 
CSS
CSSCSS
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
Shawn Calvert
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1
beretta21
 
Css Basics
Css BasicsCss Basics
Css Basics
Jay Patel
 

What's hot (20)

How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Css
CssCss
Css
 
CSS
CSS CSS
CSS
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
css.ppt
css.pptcss.ppt
css.ppt
 
CSS
CSSCSS
CSS
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Css
CssCss
Css
 
What is CSS?
What is CSS?What is CSS?
What is CSS?
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
Css
CssCss
Css
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
Class 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & IdsClass 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & Ids
 
CSS
CSSCSS
CSS
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1
 
Css Basics
Css BasicsCss Basics
Css Basics
 

Viewers also liked

[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)
Hyejin Oh
 
JakartaJS - How I Learn Javascript From Basic
JakartaJS - How I Learn Javascript From BasicJakartaJS - How I Learn Javascript From Basic
JakartaJS - How I Learn Javascript From Basic
Irfan Maulana
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to htmlvikasgaur31
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
Mai Moustafa
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
jeroenvdmeer
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
MayaLisa
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
Shawn Calvert
 

Viewers also liked (11)

Basic css-tutorial
Basic css-tutorialBasic css-tutorial
Basic css-tutorial
 
[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)
 
JakartaJS - How I Learn Javascript From Basic
JakartaJS - How I Learn Javascript From BasicJakartaJS - How I Learn Javascript From Basic
JakartaJS - How I Learn Javascript From Basic
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 

Similar to CSS Basic and Common Errors

Css
CssCss
Css
CssCss
Rational HATS and CSS
Rational HATS and CSSRational HATS and CSS
Rational HATS and CSS
Strongback Consulting
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
Css
CssCss
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)
Rafi Haidari
 
HTML to CSS Basics Exer 2.pptx
HTML to CSS Basics Exer 2.pptxHTML to CSS Basics Exer 2.pptx
HTML to CSS Basics Exer 2.pptx
JJFajardo1
 
Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
Programmer Blog
 
CSS 101
CSS 101CSS 101
CSS 101
dunclair
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
QA TrainingHub
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
Folasade Adedeji
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2Shawn Calvert
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to cssBulldogs83
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to cssBulldogs83
 
Css basics
Css basicsCss basics
Css basics
mirza asif haider
 

Similar to CSS Basic and Common Errors (20)

Css
CssCss
Css
 
Css
CssCss
Css
 
Rational HATS and CSS
Rational HATS and CSSRational HATS and CSS
Rational HATS and CSS
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)
 
HTML to CSS Basics Exer 2.pptx
HTML to CSS Basics Exer 2.pptxHTML to CSS Basics Exer 2.pptx
HTML to CSS Basics Exer 2.pptx
 
Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
 
Css
CssCss
Css
 
CSS 101
CSS 101CSS 101
CSS 101
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
 
David Weliver
David WeliverDavid Weliver
David Weliver
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
Css
CssCss
Css
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
 
Css basics
Css basicsCss basics
Css basics
 
Css
CssCss
Css
 

More from Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
Hock Leng PUAH
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
Hock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
Hock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
Hock Leng PUAH
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
Hock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
Hock Leng PUAH
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
Hock Leng PUAH
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
Hock Leng PUAH
 
Responsive design
Responsive designResponsive design
Responsive design
Hock Leng PUAH
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
Hock Leng PUAH
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
Hock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
Hock Leng PUAH
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
Hock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
Hock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
Hock Leng PUAH
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
Hock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
Hock Leng PUAH
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
Hock Leng PUAH
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker Students
Hock Leng PUAH
 

More from Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker Students
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

CSS Basic and Common Errors

  • 1. Using the CSS Prepared by: Sanjay Raval | http://www.usableweb.in/
  • 2. What is CSS? CSS is a language that’s used to define the formatting applied to a Website, including colors, background images, typefaces (fonts), margins, and indentation. Let’s look at a basic example to see how this is done. <!DOCTYPE html> <html> <head> <title>A Simple Page</title> <style type="text/css"> h1, h2 { font-family: sans-serif; color: #3366CC; } </style> </head> <body> <h1>First Title</h1><p>…</p> <h2>Second Title</h2><p>…</p> <h2>Third Title</h2><p>…</p> </body> </html>
  • 3. Using CSS in HTML lnline Styles The simplest method of adding CSS styles to your web pages is to use inline styles. An inline style is applied via the style attribute, like this: <p style="font-family: sans-serif; color: #3366CC;"> Amazingly few discotheques provide jukeboxes. </p> Inline styles have two major disadvantages: 1) They can’t be reused. For example, if we wanted to apply the style above to another p element, we would have to type it out again in that element’s style attribute. 2) Additionally, inline styles are located alongside the page’s markup, making the code difficult to read and maintain.
  • 4. Using CSS in HTML Embedded or Internal Styles In this approach, you can declare any number of CSS styles by placing them between the opening and closing <style> tags, as follows: <style type="text/css"> CSS Styles here </style> While it’s nice and simple, the <style>tag has one major disadvantage: if you want to use a particular set of styles throughout your site, you’ll have to repeat those style definitions within the style element at the top of every one of your site’s pages.
  • 5. Using CSS in HTML External Style Sheets An external style sheet is a file (usually given a .css filename) that contains a web site’s CSS styles, keeping them separate from any one web page. Multiple pages can link to the same .css file, and any changes you make to the style definitions in that file will affect all the pages that link to it. To link a document to an external style sheet (say, styles.css), we simply place a link element in the document’s header: <link rel="stylesheet" type="text/css" href="styles.css" />
  • 6. CSS Selectors Every CSS style definition has two components:  A list of one or more selectors, separated by commas, define the element or elements to which the style will be applied.  The declaration block specifies what the style actually does.
  • 7. CSS Selectors Type Selectors – Tag Selector By naming a particular HTML element, you can apply a style rule to every occurrence of that element in the document. For example, the following style rule might be used to set the default font for a web site: p, td, th, div, dl, ul, ol { font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 1em; color: #000000; }
  • 8. CSS Selectors Class Selectors CSS classes comes in when you want to assign different styles to identical elements that occur in different places within your document. Consider the following style, which turns all the paragraph text on a page blue: p { color: #0000FF; } Great! But what would happen if you had a sidebar on your page with a blue background? You wouldn’t want the text in the sidebar to display in blue as well—then it would be invisible. What you need to do is define a class for your sidebar text, then assign a CSS style to that class. To create a paragraph of the sidebarclass, first add a classattribute to the opening tag: <p class="sidebar"> This text will be white, as specified by the CSS style definition below. </p>
  • 9. CSS Selectors Class Selectors Now we can write the style for this class: p { color: #0000FF; } .sidebar { color: #FFFFFF; } This second rule uses a class selector to indicate that the style should be applied to any element of the sidebar class. The period indicates that we’re naming a class—not an HTML element.
  • 10. CSS Selectors ID Selectors In contrast with class selectors, ID selectors are used to select one particular element, rather than a group of elements. To use an ID selector, first add an id attribute to the element you wish to style. It’s important that the ID is unique within the document: <p id="tagline">This paragraph is uniquely identified by the ID "tagline".</p> To reference this element by its ID selector, we precede the id with a hash (#). For example, the following rule will make the above paragraph white: #tagline { color: #FFFFFF; } ID selectors can be used in combination with the other selector types. #tagline .new { font-weight: bold; color: #FFFFFF; }
  • 11. CSS Selectors Descendant or Compound Selectors A descendant selector will select all the descendants of an element. p { color: #0000FF; } .sidebar p { color: #FFFFFF; } <div class="sidebar"> <p>This paragraph will be displayed in white.</p> <p>So will this one.</p> </div> In this case, because our page contains a div element that has a class of sidebar, the descendant selector .sidebar p refers to all p elements inside that div.
  • 12. CSS Selectors Child Selectors A descendant selector will select all the descendants of an element, a child selector only targets the element’s immediate descendants, or “children.” Consider the following markup: <div class="sidebar"> <p>This paragraph will be displayed in white.</p> <p>So will this one.</p> <div class="tagline"> <p>If we use a descendant selector, this will be white too. But if we use a child selector, it will be blue.</p> </div> </div>
  • 13. CSS Selectors Child Selectors In this example, the descendant selector we saw in the previous section would match the paragraphs that are nested directly within div.sidebar as well as those inside div.tagline. If you didn’t want this behavior, and you only wanted to style those paragraphs that were direct descendants of div.sidebar, you’d use a child selector. A child selector uses the > character to specify a direct descendant. Here’s the new CSS, which turns only those paragraphs directly inside .sidebar (but not those within .tagline) white: p { color: #0000FF; } .sidebar>p { color: #FFFFFF; } Note: Unfortunately, Internet Explorer 6 doesn’t support the child selector.
  • 15. ID vs. Class What An ID refers to a unique instance in a document, or something that will only appear once on a page. For example, common uses of IDs are containing elements such as page wrappers, headers, and footers. On the other hand, a CLASS may be used multiple times within a document, on multiple elements. A good use of classes would be the style definitions for links, or other types of text that might be repeated in different areas on a page. In a style sheet, an ID is preceded by a hash mark (#), and might look like the following: #header { height:50px; } #footer { height:50px; } #sidebar { width:200px; float:left; } #contents { width:600px; }
  • 16. ID vs. Class What Classes are preceded by a dot (.). An example is given below. .error { font-weight:bold; color:#C00; } .btn{ background:#98A520; font-weight:bold; font-size:90%; height:24px; color:#fff; }
  • 17. Redundant Units for Zero Values The following code doesn't need the unit specified if the value is zero. padding:0px 0px 5px 0px; It can be written instead like this: padding:0 0 5px 0; Don't waste bytes by adding units such as px, pt, em, etc, when the value is zero. The only reason to do so is when you want to change the value quickly later on. Otherwise declaring the unit is meaningless. Zero pixels is the same as zero points.
  • 18. Avoid Repetition We should avoid using several lines when just one line will do. For example, when setting borders, some people set each side separately: border-top:1px solid #00f; border-right:1px solid #00f; border-bottom:1px solid #00f; border-left:1px solid #00f; But why? When each border is the same! Instead it can be like: border:1px solid #00f;
  • 19. Excess Whitespace Usually we have tendency to include whitespace in the code to make it readable. It'll only make the stylesheet bigger, meaning the bandwidth usage will be higher. Of course it's wise to leave some space in to keep it readable.
  • 20. Grouping Identical Styles together So when we want a same style to a couple of elements. It is good to group them together and define the style instead of defining the style for each element separately. h1, p, #footer, .intro { font-family:Arial,Helvetica,sans-serif; } It will also make updating the style much easier.
  • 21. Margin vs. Padding As margins and paddings are generally be used interchangeably, it is important to know the difference. It will give you greater control over your layouts. Margin refers to the space around the element, outside of the border. Padding refers to the space inside of the element, within the border. Example: No Padding, 10px Margin p { border: 1px solid #0066cc; margin:10px; padding:0; } Result:
  • 22. Margin vs. Padding Example: No Margin, 10px Padding p { border: 1px solid #0066cc; padding:10px; margin:0; } Result: