SlideShare a Scribd company logo
1 of 10
What is CSS?
 CSS stands for Cascading Style Sheets and it is the language
used to style the visual presentation of web pages.
 CSS is the language that tells web browsers how to render the
different parts of a web page.
 Every item or element on a web page is part of a document
written in a markup language.
 In most cases, HTML is the markup language, but there are
other languages in use such as XML.
CSS Syntax
CSS syntax includes selectors, properties, values, declarations,
declaration blocks, rulesets, at-rules, and statements.
 A selector is a code snippet used to identify the web page element or
elements that are to be affected by the styles.
 A property is the aspect of the element that is to be affected. For
example, color, padding, margin, and background are some of the
most commonly used CSS properties.
 A value is used to define a property. For example, the property color
might be given the value of red like this: color: red;.
 The combination of a property and a value is called a declaration.
 In many cases, multiple declarations are applied to a single selector.
A declaration block is the term used to refer to all of the declarations
applied to a single selector.
 A single selector and the declaration block that follows it in
combination are referred to as a ruleset.
An Example of CSS Syntax
h1 { color: red; font-size: 3em; text-decoration: underline; }
By using h1 as the selector, we are saying that every level 1 heading on the web
page should follow the declarations contained in this ruleset.
The ruleset contains three declarations:
 color:red;
 font-size: 3em;
 text-decoration: underline;
color, font-size, and text-decoration are all properties. There are literally
hundreds of CSS properties you can use, but only a few dozen are commonly
used.
We applied the values red, 3em, and underline to the properties we used. Each
CSS property is defined to acceptvalues formatted in a specific way.
When to Use Classes
 Use classes when there are multiple elements on a single web page that
need to be styled.
 For example, let’s say that you want links in the page header and footer to
be styled in a consistent manner, but not the same way as the links in the
bodyof the page.
 To pinpoint those links you could add a class to each of those links or the
container holding the links.
 Then, you could specify the styles using the class and be sure that they
would only be applied to the links with that class attribute.
When to Use IDs
 Use IDs for elements that only appear once on a web page.
 For example, if you’re using an HTML unordered list for your site
navigation, you could use an ID such as nav to create a unique hook for
that list.
Here’s an example of the HTML and CSS codefor a simple navigation bar for a
basic e-commerce site.
<style>
#nav {
background: lightgray;
overflow: auto;
}
#nav li {
float: left;
padding: 10px;
}
#nav li:hover {
background: gray;
}
</style>
<ul id="nav">
<li><a href="">Home</a></li>
<li><a href="">Shop</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Contact Us</a></li>
</ul>
Inline Styles
 Inline styles are applied to specific HTML elements.
 The HTML attribute style is used to define rules that only apply to that
specific element. Here’s a look at the syntax for writing inline styles.
<h1 style="color:red; padding:10px; text-
decoration:underline;">Example Heading</h1>
Internal Stylesheets
 An internal stylesheet is a block of CSS added to an HTML document
head element.
 The style element is used between the opening and closing head tags, and
all CSS declarations are added between the style tags.
We can duplicate the inline styles from the codeabove in an internal stylesheet
using this syntax.
<head> <style> h1 { color: red; padding: 10px; text-decoration: underline; }
</style> </head> <body> <h1>Example Heading</h1> </body>
External Stylesheets
 External stylesheets are documents containing nothing other than CSS
statements.
 The rules defined in the document are linked to one or more HTML
documents by using the link tag within the head element of the HTML
document.
To use an external stylesheet, first create the CSS document.
/************************************************* Save with a name
ending in .css suchas styles.css
*************************************************/
h1 { color: red; padding: 10px; text-decoration: underline; }
Cascading Inheritance
Why are CSS styles called cascading?
 When multiple rules are written that conflict with each other, the last rule
written will be implemented.
 In this way, styles cascadedownward and the last rule written is applied.
Let’s look at an example. Let’s write two CSS rules in an internal stylesheet that
directly contradict each other.
<head> <style> p {color: red;} p {color: blue;} </style> </head> <body>
<p>What color will the text of this paragraph be?</p> </body>
Uses Of CSS
CSS can be used to turn an HTML document into a professional, polished
design. Here are a few of the things you can accomplish wish CSS:
 Create a flexible grid for designing fully responsive websites that render
beautifully on any device.
 Style everything from typography, to tables, to forms, and more.
 Position elements on a web page relative to one another using properties such as
float, position, overflow, flex, and box-sizing.
 Add background images to any element.
 Create shapes, interactions, and animations.
The Box Model
If you plan to use CSS to build web page layouts, one of the first topics to
master is the box model. The box model is a way of visualizing and
understanding how each item on a web page is a combination of content,
padding, border, and margin.
CSS Layout - float and clear
The CSS float property specifies how an element should float.
The CSS clear property specifies what elements can float beside the
cleared element and on which side.
The float Property
The float property is used for positioning and formatting content e.g. let an
image float left to the text in a container.
The float property can have one of the following values:
 left - The element floats to the left of its container
 right- The element floats to the right of its container
 none - The element does not float (will be displayed just where it
occurs in the text). This is default
 inherit - The element inherits the float value of its parent
In its simplest use, the float property can be used to wrap text around
images.
Example - float: right;
The following example specifies that an image should float to the right in a
text:
img {
float: right;
}
Example - float: left;
The following example specifies that an image should float to the left in a
text:
img {
float: left;
}
Example - No float
In the following example the image will be displayed just where it occurs in
the text (float: none;):
img {
float: none;
}
The clearfix Hack
If an element is taller than the element containing it, and it is floated, it will
"overflow" outside of its container:
Then we can add overflow: auto; to the containing element to fix this
problem:
.clearfix {
overflow: auto;
}
Grid of Boxes / Equal Width Boxes
* {
box-sizing: border-box;
}
.box {
float: left;
width: 33.33%; /* three boxes (use 25% for four, and 50% for two, etc)
*/
padding: 50px; /* if you want space between the images */
}
What is box-sizing?
You can easily create three floating boxes side by side. However, when you
add something that enlarges the width of each box (e.g. padding or borders),
the box will break. The box-sizing property allows us to include the padding
and border in the box's total width (and height), making sure that the
padding stays inside of the box and that it does not break.
Images Side By Side
.img-container {
float: left;
width: 33.33%; /* three containers (use 25% for four, and 50% for two,
etc) */
padding: 5px; /* if you want space between the images */
}

More Related Content

What's hot

Html_Day_Three(W3Schools)
Html_Day_Three(W3Schools)Html_Day_Three(W3Schools)
Html_Day_Three(W3Schools)Rafi Haidari
 
CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)Ajay Khatri
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheetMichael Jhon
 
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 of css
Introduction of cssIntroduction of css
Introduction of cssDinesh Kumar
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)Harshita Yadav
 
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
 
Cascading Style Sheet | CSS
Cascading Style Sheet | CSSCascading Style Sheet | CSS
Cascading Style Sheet | CSSMSA Technosoft
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)Rafi Haidari
 
Css introduction
Css introductionCss introduction
Css introductionSridhar P
 
CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)Rafi Haidari
 
CSS_Day_Two (W3schools)
CSS_Day_Two (W3schools)CSS_Day_Two (W3schools)
CSS_Day_Two (W3schools)Rafi Haidari
 

What's hot (20)

Css
CssCss
Css
 
Html_Day_Three(W3Schools)
Html_Day_Three(W3Schools)Html_Day_Three(W3Schools)
Html_Day_Three(W3Schools)
 
CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)CSS Basics (Cascading Style Sheet)
CSS Basics (Cascading Style Sheet)
 
Css
CssCss
Css
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
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 of css
Introduction of cssIntroduction of css
Introduction of css
 
CSS
CSS CSS
CSS
 
Cascading style sheets (CSS)
Cascading style sheets (CSS)Cascading style sheets (CSS)
Cascading style sheets (CSS)
 
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
 
Css
CssCss
Css
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Cascading Style Sheet | CSS
Cascading Style Sheet | CSSCascading Style Sheet | CSS
Cascading Style Sheet | CSS
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)
 
Web Development - Lecture 3
Web Development - Lecture 3Web Development - Lecture 3
Web Development - Lecture 3
 
Css introduction
Css introductionCss introduction
Css introduction
 
CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)
 
Css
CssCss
Css
 
CSS_Day_Two (W3schools)
CSS_Day_Two (W3schools)CSS_Day_Two (W3schools)
CSS_Day_Two (W3schools)
 

Similar to What is CSS? Understanding the Basics (20)

Css
CssCss
Css
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
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
 
Css
CssCss
Css
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
Css.prabu
Css.prabuCss.prabu
Css.prabu
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
 
Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 
Css - Tutorial
Css - TutorialCss - Tutorial
Css - Tutorial
 
Lecture-6.pptx
Lecture-6.pptxLecture-6.pptx
Lecture-6.pptx
 
Css basics
Css basicsCss basics
Css basics
 
Unit 2.1
Unit 2.1Unit 2.1
Unit 2.1
 
Css
CssCss
Css
 
Css jon duckett - flashcards
Css   jon duckett - flashcardsCss   jon duckett - flashcards
Css jon duckett - flashcards
 
Css
CssCss
Css
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

What is CSS? Understanding the Basics

  • 1. What is CSS?  CSS stands for Cascading Style Sheets and it is the language used to style the visual presentation of web pages.  CSS is the language that tells web browsers how to render the different parts of a web page.  Every item or element on a web page is part of a document written in a markup language.  In most cases, HTML is the markup language, but there are other languages in use such as XML.
  • 2. CSS Syntax CSS syntax includes selectors, properties, values, declarations, declaration blocks, rulesets, at-rules, and statements.  A selector is a code snippet used to identify the web page element or elements that are to be affected by the styles.  A property is the aspect of the element that is to be affected. For example, color, padding, margin, and background are some of the most commonly used CSS properties.  A value is used to define a property. For example, the property color might be given the value of red like this: color: red;.  The combination of a property and a value is called a declaration.  In many cases, multiple declarations are applied to a single selector. A declaration block is the term used to refer to all of the declarations applied to a single selector.  A single selector and the declaration block that follows it in combination are referred to as a ruleset.
  • 3. An Example of CSS Syntax h1 { color: red; font-size: 3em; text-decoration: underline; } By using h1 as the selector, we are saying that every level 1 heading on the web page should follow the declarations contained in this ruleset. The ruleset contains three declarations:  color:red;  font-size: 3em;  text-decoration: underline; color, font-size, and text-decoration are all properties. There are literally hundreds of CSS properties you can use, but only a few dozen are commonly used. We applied the values red, 3em, and underline to the properties we used. Each CSS property is defined to acceptvalues formatted in a specific way. When to Use Classes  Use classes when there are multiple elements on a single web page that need to be styled.  For example, let’s say that you want links in the page header and footer to be styled in a consistent manner, but not the same way as the links in the bodyof the page.  To pinpoint those links you could add a class to each of those links or the container holding the links.  Then, you could specify the styles using the class and be sure that they would only be applied to the links with that class attribute. When to Use IDs  Use IDs for elements that only appear once on a web page.  For example, if you’re using an HTML unordered list for your site navigation, you could use an ID such as nav to create a unique hook for that list.
  • 4. Here’s an example of the HTML and CSS codefor a simple navigation bar for a basic e-commerce site. <style> #nav { background: lightgray; overflow: auto; } #nav li { float: left; padding: 10px; } #nav li:hover { background: gray; } </style> <ul id="nav"> <li><a href="">Home</a></li> <li><a href="">Shop</a></li> <li><a href="">About Us</a></li> <li><a href="">Contact Us</a></li> </ul> Inline Styles  Inline styles are applied to specific HTML elements.  The HTML attribute style is used to define rules that only apply to that specific element. Here’s a look at the syntax for writing inline styles.
  • 5. <h1 style="color:red; padding:10px; text- decoration:underline;">Example Heading</h1> Internal Stylesheets  An internal stylesheet is a block of CSS added to an HTML document head element.  The style element is used between the opening and closing head tags, and all CSS declarations are added between the style tags. We can duplicate the inline styles from the codeabove in an internal stylesheet using this syntax. <head> <style> h1 { color: red; padding: 10px; text-decoration: underline; } </style> </head> <body> <h1>Example Heading</h1> </body> External Stylesheets  External stylesheets are documents containing nothing other than CSS statements.  The rules defined in the document are linked to one or more HTML documents by using the link tag within the head element of the HTML document. To use an external stylesheet, first create the CSS document. /************************************************* Save with a name ending in .css suchas styles.css *************************************************/ h1 { color: red; padding: 10px; text-decoration: underline; } Cascading Inheritance Why are CSS styles called cascading?  When multiple rules are written that conflict with each other, the last rule written will be implemented.  In this way, styles cascadedownward and the last rule written is applied. Let’s look at an example. Let’s write two CSS rules in an internal stylesheet that directly contradict each other.
  • 6. <head> <style> p {color: red;} p {color: blue;} </style> </head> <body> <p>What color will the text of this paragraph be?</p> </body> Uses Of CSS CSS can be used to turn an HTML document into a professional, polished design. Here are a few of the things you can accomplish wish CSS:  Create a flexible grid for designing fully responsive websites that render beautifully on any device.  Style everything from typography, to tables, to forms, and more.  Position elements on a web page relative to one another using properties such as float, position, overflow, flex, and box-sizing.  Add background images to any element.  Create shapes, interactions, and animations. The Box Model If you plan to use CSS to build web page layouts, one of the first topics to master is the box model. The box model is a way of visualizing and understanding how each item on a web page is a combination of content, padding, border, and margin.
  • 7. CSS Layout - float and clear The CSS float property specifies how an element should float. The CSS clear property specifies what elements can float beside the cleared element and on which side. The float Property The float property is used for positioning and formatting content e.g. let an image float left to the text in a container. The float property can have one of the following values:  left - The element floats to the left of its container  right- The element floats to the right of its container  none - The element does not float (will be displayed just where it occurs in the text). This is default  inherit - The element inherits the float value of its parent
  • 8. In its simplest use, the float property can be used to wrap text around images. Example - float: right; The following example specifies that an image should float to the right in a text: img { float: right; } Example - float: left; The following example specifies that an image should float to the left in a text: img { float: left; } Example - No float In the following example the image will be displayed just where it occurs in the text (float: none;): img { float: none; }
  • 9. The clearfix Hack If an element is taller than the element containing it, and it is floated, it will "overflow" outside of its container: Then we can add overflow: auto; to the containing element to fix this problem: .clearfix { overflow: auto; } Grid of Boxes / Equal Width Boxes
  • 10. * { box-sizing: border-box; } .box { float: left; width: 33.33%; /* three boxes (use 25% for four, and 50% for two, etc) */ padding: 50px; /* if you want space between the images */ } What is box-sizing? You can easily create three floating boxes side by side. However, when you add something that enlarges the width of each box (e.g. padding or borders), the box will break. The box-sizing property allows us to include the padding and border in the box's total width (and height), making sure that the padding stays inside of the box and that it does not break. Images Side By Side .img-container { float: left; width: 33.33%; /* three containers (use 25% for four, and 50% for two, etc) */ padding: 5px; /* if you want space between the images */ }