SlideShare a Scribd company logo
1 of 25
Download to read offline
HTML and CSS basics
Lecture 2
CGS 3066 Fall 2016
September 15, 2016
Basics - Frimly Grasp It!!
Formatting
I You cannot change the output by adding extra spaces or lines
in HTML code. The browser will ignore whitespace.
I New horizontal line: <hr >
I New Line tag: <br >
I Whitespace: &nbsp
I There are a variety of ways to introduce tab spacing, most of
them using CSS.
Special formatting tags
Certain text usually has a conventional formatting, HTML has a
few special formatting tags, usueful especially for computer code.
I <pre>- for preformatted text. Forces the browser to render
white space as-is.
I <kbd>- for specifying keyboard input.
I <samp>- for specifying console output.
I <code>- for specifying computer code. Monotype font.
Ignores whitespace.
Text Formatting
I Use tags for formatting output.
I A list of formatting tags:
I <b>: defines bold text
I <i>: defines italic text
I <sub>: defines subscripted text
I <sup>: defines superscripted text
I <mark>: defines marked/highlighted text
Hyperlink
I The <a>tag defines hyperlink.
I A hyperlink is a word, group of words, or image that you can
click on to jump to another web page.
I The href is the most important attribute, which indicates the
links destination.
<a href=“http://www.google.com”>Go To Google </a>
I The target attribute specifies where to open the linked
document.
I blank: in a new window or tab
I self: in the same frame as it was clicked (default)
Images
I <img>tag is always an empty tag. It contains attributes and
has no closing tag.
I You need to use the src attribute. The value of this attribute
is the URL of the image.
Syntax: <img src=“sampleImage.JPEG” alt=“hint” >
I alt defines the text for an image when the image cannot be
displayed.
I The width and height attributes define the size of the image.
HTML Table Element
I To start off a tables, use the <table>
I A table consists of rows <tr>. Each row is divided into data
cells <td>(td stands for table data)
I A <td>tag can contain text, links, images, lists, forms, and
other tables.
HTML Lists
I Lists can be ordered and unordered.
I An unordered list starts with the <ul>tag.
I An ordered list starts with the <ol>tag.
I Each item starts with the <li>tag.
I A description list is a list of items with a description of each
term/name.
I The <dl>tag defines a description list. <dl>is used with
<dt>(defines items) and <dd>(describes each item).
Block and Inline Elements
I HTML elements are either block level elements or inline
elements.
I Block level Elements start with a new line.
E.g., <p>, <table>, <div>
I Inline elements are displayed without a new line.
E.g., <b>, <td>, <a>, <img>
<span>element
I <span>element is an inline element that can be used as a
container for text.
I <span>element usually is used to set style to parts of the
text.
DIV tag
I The <div>tag defines a division or a section in an HTML
document.
I The <div>tag is used to group block-elements to format
them with CSS.
CSS Syntax
I A CSS file consists of rule set, which define the presentation
element for a particular part of the HTML document.
I A CSS rule set consists of a selector and a declaration block.
I A Rule Set has a selector and a declaration block.
I The declaration block is enclosed in { }.
I The declaration block contains one or more declarations
separated by semicolons.
I Each declaration includes a property name and a value,
separated by a colon.
I To make the CSS code more readable, you can put one
declaration on each line.
CSS Comments
I CSS comments follow the multiline C comment syntax.
I A CSS comment starts with /* and ends with */.
I Comments can also span multiple lines and are ignored by
browsers.
I Single line comments can start with “//”.
CSS Selectors
I CSS selectors allow you to select and manipulate HTML
elements.
I They are used to “find” HTML elements based on id, classes,
types, attributes, values of attributes, etc.
I Typically, selectors are one of 3 kinds:
I id selector
I element selector
I class selector
Element Selector
I The element selector selects elements based on the element
name.
I Applied to all elements with the same name (tag).
I Example:
p {
text-align: center;
color: red;
}
ID Selector
I The id selector uses the id attribute of an HTML tag to find
the specific element.
I An id should be unique within a page.
I To find an element with a specific id, write the character
formerly known as the pound (#), followed by the id of the
element.
I Example
#para1 {
text-align: center;
color: red;
}
Class Selector
I The class selector finds elements with the specific class.
I The class selector uses the HTML class attribute.
I To find elements with a specific class, write a period
character, followed by the name of the class.
I Example:
.center {
text-align: center;
color: red;
}
I You can also specify that only specific HTML elements should
be affected by a class.
I p.center {
text-align: center;
color: red;
}
Grouping Selectors
I In style sheets there are often elements with the same style.
I In the interest of code minimization, we can group selectors.
I Selectors are separated by commas.
I Example:
h1, h2, p {
text-align: center;
color: red;
}
Adding CSS to your HTML document
There are 3 ways to do styling
I Inline Style - Style elements are included as HTML attributes.
I Internal Style Sheets - A <style>tag is used in the HTML
document to specify the presentation elements. External
Style Sheets - A separate “.css” file is used as a part of your
set of documents. It contains all the styling elements.
Inline CSS
I What little styling weve been doing so far.
I Mixes content with presentation. Loses many of the
advantages of a style sheet.
I Used very rarely (when very few elements require styling).
I Add the style attribute to the relevant tag. The style attribute
can contain any CSS property.
I Example:
<h1 style=“color:blue; margin-left:30px;”>This is a heading.
</h1>
Internal CSS
I Used when the current document has a unique style.
I A <style>tag is used under the <head>tag of the document
to define the styles.
I The content of the <style>tag follows CSS syntax.
I Example:
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
External CSS
I Used when a style is applied to many pages (like a theme).
I The look of the webpage can be changed by just changing one
file.
I Each page must include a link to the style sheet with the
<link>tag. The <link>tag goes inside the head section.
I An external stylesheet is written as a separate file with a
“.css” extension.
I The file should go into the same relative path as the rest of
the files (or can be referred by absolute path).
I The external stylesheet should not contain any HTML tags.
External Stylesheet Example
I myStyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
I In the head tag of the HTML document
<head>
<link rel=“stylesheet” type=“text/css” href=“mystyle.css”>
</head>
Why “Cascading”?
I Multiple styles will cascade into one.
I Styles can be specified:
I inside an HTML element
I inside the head section of an HTML page
I in an external CSS file
I Generally speaking we can say that all the styles will
“cascade” into a new “virtual” style sheet by the following
rules, where number one has the highest priority:
1. Inline style (inside an HTML element)
2. Internal style sheet (in the head section)
3. External style sheet
4. Browser default

More Related Content

Similar to HTML2.pdf

Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Erin M. Kidwell
 
Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)John Bosco Javellana, MAEd.
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)Rafi Haidari
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style SheetsMukesh Tekwani
 
Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Aditya Dwivedi
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
Html tutorials by www.dmdiploma.com
Html tutorials by www.dmdiploma.comHtml tutorials by www.dmdiploma.com
Html tutorials by www.dmdiploma.comShwetaAggarwal56
 
INTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfINTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfDineshKumar522328
 
Html, css and jquery introduction
Html, css and jquery introductionHtml, css and jquery introduction
Html, css and jquery introductioncncwebworld
 
Css tutorial
Css tutorialCss tutorial
Css tutorialvedaste
 
Html & Html5 from scratch
Html & Html5 from scratchHtml & Html5 from scratch
Html & Html5 from scratchAhmad Al-ammar
 

Similar to HTML2.pdf (20)

Css introduction
Css  introductionCss  introduction
Css introduction
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
Girl Develop It Cincinnati: Intro to HTML/CSS Class 2
 
Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)
 
Webithon Workshop
Webithon WorkshopWebithon Workshop
Webithon Workshop
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Html n CSS
Html n CSSHtml n CSS
Html n CSS
 
Html
HtmlHtml
Html
 
Html
HtmlHtml
Html
 
Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...
 
PHP HTML CSS Notes
PHP HTML CSS  NotesPHP HTML CSS  Notes
PHP HTML CSS Notes
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Html tutorials by www.dmdiploma.com
Html tutorials by www.dmdiploma.comHtml tutorials by www.dmdiploma.com
Html tutorials by www.dmdiploma.com
 
INTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdfINTERNSHIP PROJECT PPT RAJ HZL.pdf
INTERNSHIP PROJECT PPT RAJ HZL.pdf
 
Html presentation
Html presentationHtml presentation
Html presentation
 
Html, css and jquery introduction
Html, css and jquery introductionHtml, css and jquery introduction
Html, css and jquery introduction
 
Web technology Unit-II Part-C
Web technology Unit-II Part-CWeb technology Unit-II Part-C
Web technology Unit-II Part-C
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 
Html & Html5 from scratch
Html & Html5 from scratchHtml & Html5 from scratch
Html & Html5 from scratch
 
Css
CssCss
Css
 

Recently uploaded

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 

HTML2.pdf

  • 1. HTML and CSS basics Lecture 2 CGS 3066 Fall 2016 September 15, 2016
  • 2. Basics - Frimly Grasp It!!
  • 3. Formatting I You cannot change the output by adding extra spaces or lines in HTML code. The browser will ignore whitespace. I New horizontal line: <hr > I New Line tag: <br > I Whitespace: &nbsp I There are a variety of ways to introduce tab spacing, most of them using CSS.
  • 4. Special formatting tags Certain text usually has a conventional formatting, HTML has a few special formatting tags, usueful especially for computer code. I <pre>- for preformatted text. Forces the browser to render white space as-is. I <kbd>- for specifying keyboard input. I <samp>- for specifying console output. I <code>- for specifying computer code. Monotype font. Ignores whitespace.
  • 5. Text Formatting I Use tags for formatting output. I A list of formatting tags: I <b>: defines bold text I <i>: defines italic text I <sub>: defines subscripted text I <sup>: defines superscripted text I <mark>: defines marked/highlighted text
  • 6. Hyperlink I The <a>tag defines hyperlink. I A hyperlink is a word, group of words, or image that you can click on to jump to another web page. I The href is the most important attribute, which indicates the links destination. <a href=“http://www.google.com”>Go To Google </a> I The target attribute specifies where to open the linked document. I blank: in a new window or tab I self: in the same frame as it was clicked (default)
  • 7. Images I <img>tag is always an empty tag. It contains attributes and has no closing tag. I You need to use the src attribute. The value of this attribute is the URL of the image. Syntax: <img src=“sampleImage.JPEG” alt=“hint” > I alt defines the text for an image when the image cannot be displayed. I The width and height attributes define the size of the image.
  • 8. HTML Table Element I To start off a tables, use the <table> I A table consists of rows <tr>. Each row is divided into data cells <td>(td stands for table data) I A <td>tag can contain text, links, images, lists, forms, and other tables.
  • 9. HTML Lists I Lists can be ordered and unordered. I An unordered list starts with the <ul>tag. I An ordered list starts with the <ol>tag. I Each item starts with the <li>tag. I A description list is a list of items with a description of each term/name. I The <dl>tag defines a description list. <dl>is used with <dt>(defines items) and <dd>(describes each item).
  • 10. Block and Inline Elements I HTML elements are either block level elements or inline elements. I Block level Elements start with a new line. E.g., <p>, <table>, <div> I Inline elements are displayed without a new line. E.g., <b>, <td>, <a>, <img>
  • 11. <span>element I <span>element is an inline element that can be used as a container for text. I <span>element usually is used to set style to parts of the text.
  • 12. DIV tag I The <div>tag defines a division or a section in an HTML document. I The <div>tag is used to group block-elements to format them with CSS.
  • 13. CSS Syntax I A CSS file consists of rule set, which define the presentation element for a particular part of the HTML document. I A CSS rule set consists of a selector and a declaration block. I A Rule Set has a selector and a declaration block. I The declaration block is enclosed in { }. I The declaration block contains one or more declarations separated by semicolons. I Each declaration includes a property name and a value, separated by a colon. I To make the CSS code more readable, you can put one declaration on each line.
  • 14. CSS Comments I CSS comments follow the multiline C comment syntax. I A CSS comment starts with /* and ends with */. I Comments can also span multiple lines and are ignored by browsers. I Single line comments can start with “//”.
  • 15. CSS Selectors I CSS selectors allow you to select and manipulate HTML elements. I They are used to “find” HTML elements based on id, classes, types, attributes, values of attributes, etc. I Typically, selectors are one of 3 kinds: I id selector I element selector I class selector
  • 16. Element Selector I The element selector selects elements based on the element name. I Applied to all elements with the same name (tag). I Example: p { text-align: center; color: red; }
  • 17. ID Selector I The id selector uses the id attribute of an HTML tag to find the specific element. I An id should be unique within a page. I To find an element with a specific id, write the character formerly known as the pound (#), followed by the id of the element. I Example #para1 { text-align: center; color: red; }
  • 18. Class Selector I The class selector finds elements with the specific class. I The class selector uses the HTML class attribute. I To find elements with a specific class, write a period character, followed by the name of the class. I Example: .center { text-align: center; color: red; } I You can also specify that only specific HTML elements should be affected by a class. I p.center { text-align: center; color: red; }
  • 19. Grouping Selectors I In style sheets there are often elements with the same style. I In the interest of code minimization, we can group selectors. I Selectors are separated by commas. I Example: h1, h2, p { text-align: center; color: red; }
  • 20. Adding CSS to your HTML document There are 3 ways to do styling I Inline Style - Style elements are included as HTML attributes. I Internal Style Sheets - A <style>tag is used in the HTML document to specify the presentation elements. External Style Sheets - A separate “.css” file is used as a part of your set of documents. It contains all the styling elements.
  • 21. Inline CSS I What little styling weve been doing so far. I Mixes content with presentation. Loses many of the advantages of a style sheet. I Used very rarely (when very few elements require styling). I Add the style attribute to the relevant tag. The style attribute can contain any CSS property. I Example: <h1 style=“color:blue; margin-left:30px;”>This is a heading. </h1>
  • 22. Internal CSS I Used when the current document has a unique style. I A <style>tag is used under the <head>tag of the document to define the styles. I The content of the <style>tag follows CSS syntax. I Example: <head> <style> body { background-color: linen; } h1 { color: maroon; margin-left: 40px; } </style> </head>
  • 23. External CSS I Used when a style is applied to many pages (like a theme). I The look of the webpage can be changed by just changing one file. I Each page must include a link to the style sheet with the <link>tag. The <link>tag goes inside the head section. I An external stylesheet is written as a separate file with a “.css” extension. I The file should go into the same relative path as the rest of the files (or can be referred by absolute path). I The external stylesheet should not contain any HTML tags.
  • 24. External Stylesheet Example I myStyle.css body { background-color: lightblue; } h1 { color: navy; margin-left: 20px; } I In the head tag of the HTML document <head> <link rel=“stylesheet” type=“text/css” href=“mystyle.css”> </head>
  • 25. Why “Cascading”? I Multiple styles will cascade into one. I Styles can be specified: I inside an HTML element I inside the head section of an HTML page I in an external CSS file I Generally speaking we can say that all the styles will “cascade” into a new “virtual” style sheet by the following rules, where number one has the highest priority: 1. Inline style (inside an HTML element) 2. Internal style sheet (in the head section) 3. External style sheet 4. Browser default