SlideShare una empresa de Scribd logo
1 de 22
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:

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Destacado

[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 BasicIrfan 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 JavascriptAmit Tyagi
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to htmlvikasgaur31
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginnersjeroenvdmeer
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTMLMayaLisa
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS PresentationShawn Calvert
 

Destacado (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 a CSS Basic and Common Errors

Similar a 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
 

Más de Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image SlideshowHock Leng PUAH
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introductionHock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingHock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash fileHock 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 birthHock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime exampleHock 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( ) functionHock 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 siteHock 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 visibleHock 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 ProjectHock 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 parallelHock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises GuideHock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connectionHock 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 SummaryHock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guideHock 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 StudentsHock Leng PUAH
 

Más de 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
 

Último

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

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: