css introduction

23
INTRO TO CSS IAT100 Spring 2010 Diliara Nasirova 1

Upload: diliara-nasirova

Post on 21-May-2015

449 views

Category:

Technology


0 download

DESCRIPTION

CSS Tutorial presentation notes prepared for IAT 100 course @SIAT, SFU Spring 2010 semester

TRANSCRIPT

Page 1: CSS Introduction

INTRO  TO  CSS  IAT100  Spring  2010    Diliara  Nasirova  

1  

Page 2: CSS Introduction

OUTLINE  

¢  Covered  in  this  lesson:  �  Overview  

¢ What  is  CSS?  ¢ Why  to  use  CSS?  

�  Structure  ¢  CSS  Syntax  Introduction  ¢  Three  places  CSS  can  be  de=ined  ¢  CSS  Syntax  Speci=ics  ¢  Cascading  Inheritance  

�  Applied  ¢  CSS  Hands-­‐on    

2  

Page 3: CSS Introduction

WHAT  IS  CSS?  

¢  Cascading  Style  Sheets  (CSS)  de=ines  the  way  website  content  is  presented.    

Visit http://www.csszengarden.com

3  

Page 4: CSS Introduction

WHERE  THE  DEFINITION  “CASCADING”  COMES  FROM?  

4  

Page 5: CSS Introduction

WHERE  THE  DEFINITION  “CASCADING”  COMES  FROM?  

 *detailed  info  later  

5  

Page 6: CSS Introduction

WHERE  THE  DEFINITION  “CASCADING”  COMES  FROM?  

*detailed  info  later  6  

Page 7: CSS Introduction

WHY  CSS?  

¢  Separate  Content  from  Form  

<font  size=“14px”>  My  First  Header  </font>  <font  size=“12px”  color=“red”  face=“Verdana”>  My  information  1  goes  here.  </font>  <font  size=“14px”>  My  Second  Header  </font>  <font  size=“12px”  color=“red”  face=“Verdana”>  Different  information  goes  here.  </font>  

The  old  way:  

7  

Page 8: CSS Introduction

WHY  CSS?  CONTINUED.  

¢  Separate  Content  from  Form  �  Content  

     

�  Form  or  Style  

<p  class=“header”>My  First  Header</p>  <p  class=“info”>My  Information  1  goes  here</p>  <p  class=“header”>My  Second  Header</p>  <p  class=“info”>Different    Information  goes  here</p>      (Speci=ic  markup  properties  like  Class  will  be  discussed  later).  

.header  {  font-­‐size:14px;}  

.info  {  font-­‐family:  verdana;    font-­‐color:  blue;    font-­‐size:  12px;    }   8  

Page 9: CSS Introduction

WHAT  DOES  THIS  SEPARATION  GET  US?  

9  

Page 10: CSS Introduction

WHAT  DOES  THIS  SEPARATION  GET  US?  

10  

Page 11: CSS Introduction

WHAT  DOES  THIS  SEPARATION  GET  US?  

11  

Page 12: CSS Introduction

THREE  CSS  DEFINITION  LOCATIONS  ¢  Inline:    the  “style”  attribute  

   ¢  Internal:  the  <style>  markup  tag  

   

¢  External:  the  .css  stylesheet  =ile  

<p>  Content  </p>  <p  style=“font-­‐color:red;  font-­‐size:10px;”>  Content  </p>  

<html>  <head>        <style>                p  {  background-­‐color:  Red;  

 font-­‐family:  serif;    font-­‐color:  White;  }  

     </style>  </head>  <body><p>Content</p></body>  </html>  

<link  rel="stylesheet"  type="text/css"  href=“mystylesheet.css"  />  12  

Page 13: CSS Introduction

CASCADING  

13  

Page 14: CSS Introduction

CSS  SYNTAX  

¢  3  Elements  to  a  CSS  Statement  �  Selector  

¢ What  HTML  sections  does  it  affect?  �  Property  

¢ What  attribute  of  that  HTML  section  will  be  affected?  �  Value  

¢ What  change  will  be  made  to  that  attribute?  

14  

Page 15: CSS Introduction

CSS  SYNTAX  

¢ Applying  a  style  to  Multiple  selectors  -­‐  separate  the  selectors  with  a  comma  (,)        

¢ Applying  Multiple  properties  -­‐  split  each  declaration  with  a  semi-­‐colon  (;)          

h1  {  color:red;  font-­‐family:calibri}

h1,  h2,  h3,  h4,  h5,  h6  {  color:  red  }  

15  

Page 16: CSS Introduction

CSS  SYNTAX:  SELECTORS  

¢ Think  of  …  

�  Web  Page  as  a  university  

�  Selectors  can  be  tags,  classes,  IDs.  Then:  ¢ Tags  as  students  ¢ Class  as  student’s  major  ¢  ID  as  student’s  ID  number    

16  

Page 17: CSS Introduction

CSS  SYNTAX:  SELECTORS  

¢ Tag  Selector  

¢  Class  Selector–  precede  the  class  with  a  dot(.)  

¢  ID  selector  precedes  with  a  "#"  symbol  

CSS:  .myinfo  {  font-­‐size:  10px;    font-­‐color:  White;  }  

 HTML:    <p  class=“myinfo” >  Content</p>  

 <div  class=“myinfo”>  Other  content</div>  

CSS:    #container{  font-­‐size:  10px;                font-­‐color:  White;  }  

HTML:          <div  id=“container”>  This  is  one  section  </div>  

CSS:    p  {font-­‐size:  10px;}  HTML:  <p>Content</p>  

17  

Page 18: CSS Introduction

EXTRA  HTML  TAGS:  DIVISION  AND  SPAN  

¢  Extra  Tags:  Div  and  Span  de=ine  sections  in  a  HTML  =ile  ¢ Div  tag  is  a  style  element  for  multiple  lines  

¢  Span  tag  is  a  style  element  for  one  line  (inline).  

¢  You  can  apply  CSS  to  Div  through  ID/Class  Selector;    

<div  id  =  “container”>            <h1>  Content  goes  here  </h1>          <p>  Content  goes  here  </p>    </div>  

<p>  Content  <span  class=“myinfo”>  goes  here  <span>  </p>    

18  

Page 19: CSS Introduction

CASCADING  INHERITANCE  

19  

Page 20: CSS Introduction

CSS  APPLIED  

¢ Hands-­‐on  CSS  Tutorial  ¢ Techbyte:  http://www.sfu.ca/~tutor/cgi-­‐bin/techbytes/Dreamweaver/dw2.html  

20  

Page 21: CSS Introduction

PRESENTATION  NOTES  

¢  Page  3:  

�  Originally  HTML  was  used  to  change  the  appearance  of  websites,  so  that  HTML  documents  eventually  turned  into  a  mixture  of  content  and  presentaRon.  This  problem  was  solved  by  W3C  (World  Wide  Web  ConsorRum)  that  created  CSS,  level  1  in  1996.  It  was  quickly  adopted  by  all  main  web  browsers.  In  1998  W3C  developed  a  more  sophisRcated  and  accurate  CSS2  followed  by  a  minor  CSS2.1  update  and  CSS3  is  currently  under  development.  CSS  is  usually  stored  in  separate  .css  style  sheets  which  can  be  re-­‐used  for  all  your  web  pages.    

�  Cascading  Style  Sheets  (CSS)  is  a  language  that  works  with  HTML  documents  for  adding  visual  style  to  web  sites,  in  other  words  for  defining  the  way  content  is  presented.  It  deals  with  colors,  fonts,  background  images,  posiRons,  width,  height,  visibility  and  many  other  things.  

¢  Page  7:  

�  Content  is  the  text  and  images,  marked  up  to  define  regions  of  specific  types  �  Form  defines  the  “style”  for  the  content    

21  

Page 22: CSS Introduction

PRESENTATION  NOTES  

¢  Page  9:  

�  Separate  Content  from  Form  ¢  Specify  the  style  once  for  every  instance  of  that  class.  

¢  Example:    Specify  the  font  once  for  all  text  on  the  HTML  page  that  you  have  idenRfied  as  a  “header”.  

¢  The  style  sheet  can  be  a  separate  file  which  all  HTML  pages  on  your  enRre  site  can  link  to.  ¢  Only  have  to  specify  the  style  once  for  your  ENTIRE  SITE  

¢  Can  change  the  style  for  your  enRre  site  by  ediRng  only  ONE  FILE.  

¢  Page  12:  

�  Note,  the  selector  for  inline  CSS  is  the  tag  which  contains  the  style  aaribute.    

22  

Page 23: CSS Introduction

RESOURCES:  

¢ Notes:    www.tagbytag.org/tutorials/css-­‐beginner/what-­‐is-­‐css    

¢  Pictures:  www.wise-­‐women.org/tutorials/csstut/  

   

23