css primer - basic stuff

17
css the very basics a primer for hk search engineers kenny tang jan kenny tang jan 2010 2010

Upload: kenshin03

Post on 16-Jan-2015

681 views

Category:

Technology


0 download

DESCRIPTION

This is so 1999...but not all developers are aware of the basics so here's a little recap for the team.

TRANSCRIPT

Page 1: Css Primer - basic stuff

css the very basicscss the very basicsa primer for hk search engineersa primer for hk search engineers

kenny tang jan 2010kenny tang jan 2010

Page 2: Css Primer - basic stuff

Before HTML4, styles were done with <font>, Before HTML4, styles were done with <font>, <br>, &nbsp;, <table> tags:<br>, &nbsp;, <table> tags:

Page 3: Css Primer - basic stuff

CSS came along with the aim of removing CSS came along with the aim of removing formatting from HTML documentsformatting from HTML documents

markup with inline stylemarkup with inline style browser renderingbrowser rendering

Page 4: Css Primer - basic stuff

CSS rules syntaxCSS rules syntax

HTML element you want HTML element you want to styleto style

property:value pairsproperty:value pairs(same line or multiple)(same line or multiple)

Page 5: Css Primer - basic stuff

Choosing the correct selector:Choosing the correct selector:

which element(s) do you want to style?which element(s) do you want to style?

One single line of text? A block of YSM One single line of text? A block of YSM ads? All content wrapped with <p> tags? ads? All content wrapped with <p> tags?

The page background?The page background?

Use Use idid, , classclass and and tagtag for differentiation for differentiation

Page 6: Css Primer - basic stuff

id - targets a id - targets a single, uniquesingle, unique element: element:

use use ## in css selector in css selector

use use idid in html tag in html tag

Page 7: Css Primer - basic stuff

class - targets class - targets multiplemultiple elements: elements:

use use ‘.’‘.’ in css selector in css selector

use use classclass in html tag in html tagtargets all elements with class “targets all elements with class “yschysmyschysm” with html ” with html

tag “tag “lili””

Page 8: Css Primer - basic stuff

tags - targets specific html elements:tags - targets specific html elements:

use use html tag namehtml tag name in css selector in css selector

no special tags needed in html tagno special tags needed in html tag

targets all elements with tag “targets all elements with tag “aa” with ” with state of “link” (static hyperlinks)state of “link” (static hyperlinks)

commonly used for removing underlines from <a> tagscommonly used for removing underlines from <a> tags

Page 9: Css Primer - basic stuff

recap of selector declarations so far:recap of selector declarations so far:

class:class:

id:id:

tags:tags:

finer-grain finer-grain targeting:targeting:

targets all targets all <a><a> links in links in hover state, which are hover state, which are enclosed by enclosed by <li><li> tags, tags,

with with classclass of of ““vsearchtabsvsearchtabs” and ” and idid of of

““searchtab_tsearchtab_t””

Page 10: Css Primer - basic stuff

styles possessed by each element are inherited styles possessed by each element are inherited from multiple sourcesfrom multiple sources

it’s up to css parsers and rendering engines (webkit, gecko) to analyze the style it’s up to css parsers and rendering engines (webkit, gecko) to analyze the style hierarchy and decide how to render each and every elementhierarchy and decide how to render each and every element

#heading1{text-align:center;color:red;} #heading1{text-align:center;color:red;} #heading1{text-align:center;color:red;} #heading1{text-align:center;color:red;} external .css fileexternal .css file

<head><head><style><style>#heading1{text-align:left;color:green;} #heading1{text-align:left;color:green;} </style></style></head></head>

<head><head><style><style>#heading1{text-align:left;color:green;} #heading1{text-align:left;color:green;} </style></style></head></head>

internal <style> blockinternal <style> block

inline styleinline style

browser rendering result:browser rendering result:

Page 11: Css Primer - basic stuff

Quick scan of fundamental css attributes:Quick scan of fundamental css attributes:

top,right,bottom,lefttop,right,bottom,left

Page 12: Css Primer - basic stuff

css browser hacks, sometimes needed for those css browser hacks, sometimes needed for those IE quirksIE quirks

Page 13: Css Primer - basic stuff

Simple FE bugs troubleshooting tips: Simple FE bugs troubleshooting tips:

1. With Firebug’s inspect tool, understand the 1. With Firebug’s inspect tool, understand the basic structurebasic structure of the page first. of the page first.

Page 14: Css Primer - basic stuff

Simple FE bugs troubleshooting tips: Simple FE bugs troubleshooting tips:

2. Drill down the DOM tree to locate the area/element you wish to check:2. Drill down the DOM tree to locate the area/element you wish to check:

““fcts_lpfcts_lp”: left rail”: left rail

““r-mr-m”: main search ”: main search results arearesults area

Page 15: Css Primer - basic stuff

Simple FE bugs troubleshooting tips: Simple FE bugs troubleshooting tips:

3. With Firebug’s inspect tools, identify the element and look at the style info 3. With Firebug’s inspect tools, identify the element and look at the style info on the right pane.on the right pane.

Page 16: Css Primer - basic stuff

Simple FE bugs troubleshooting tips: Simple FE bugs troubleshooting tips:

4. Attempt to troubleshoot/fix the problem by inserting style attributes directly 4. Attempt to troubleshoot/fix the problem by inserting style attributes directly into the style pane and observe what happens:into the style pane and observe what happens:

Page 17: Css Primer - basic stuff

Required ReadingRequired Reading

links removedlinks removed