SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
An
Introduction
to CSS
(Cascading
stylesheet)
Priya Goyal
CSS stands for Cascading Style Sheet.
Typical CSS file is a text file with an
extention.css and contains a series of
commands or rules. These rules tell the HTML how
to display.
*To create a style sheet, create a file using Notepad or Text Editor and
save it as a .css document and start writing the CSS code.
CSS Benefits
• Separates structure from presentation
• Provides advanced control of presentation
• Easy maintenance of multiple pages
• Faster page loading
• Better accessibility for disabled users
• Easy to learn
“HTML without CSS is like a piece of candy without a
pretty wrapper.”
Without CSS, HTML elements typically flow from top to
bottom of the page and position themselves to the left
by default.
With CSS help, we can create containers or DIVs to better
organize content and make a Web page visually
appealing.
Attaching a Style Sheet
Attach a style sheet to a page by adding the code to the <head> section of the HTML page.
There are 3 ways to attach CSS to a page:
1. External Style Sheet: Best used to control styling on multiple pages.
<link rel="stylesheet" type="text/css" href="css/styles.css" />
.css file
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
2. Internal Style Sheet: Best used to control styling on one page.
<style type=“text/css”>
h1 {color: red)
</style>
3. Inline Style Sheet*: CSS is not attached in the <header> but is used directly within HTML
tags.
<p style=“color: red”>Some Text</p>
CSS Rule Structure
A CSS RULE is made up of a selector
and a declaration. A declaration consists
of property and value.
selector {property: value;}
declaration
body { property: value; }
h1 { property: value; }
em { property: value; }
p { property: value; }
Universal Selector
The universal selector is an asterisk.
matches all element types in the document.
*{ }
The Type Selector
the same rules to several elements.
h1, h2, h3 {}
The Class Selector
< p class=”student” >…… < /p >
<div class=“student”>…….</div>
‘ . ‘ is used to denote a class
We can use a class selector in one of two ways here.
1)One way is to directly assign the class name ‘student’. By using this, same rules will be
applied to all elements whose class name is ‘student’.
.student {
}
2)We can apply the attributes to specific elements.
p.student {
text-align: center;
color: red;
}
The ID Selector
The id selector works just like a class selector, but works on the value of id attributes
#para1 {
text-align: center;
color: red;
}
The Border Properties
There are three properties of a border you can change:
border - color border - style border - width
The border - color Property
p {border-color:#ff0000;}
It may be
border - bottom - color
border - right - color
border - top - color
border - left – color
The border - width Property
p {border-width:4px;}
The value of the border - width property
cannot be given as a percentage.. It may be
thin
medium
Thick
Can also give
border - bottom - width
border - right - width
border - top - width
border - left - width
The border - style Property
p {border-style : solid;}
border - bottom - style
border - right - style
border - top - style
border - left - style
The padding Property
The padding property allows you to specify how much space should appear between
the content of an element and its border:
td {padding:5px;}
padding - bottom
padding - top
padding - left
padding - right
Background Color
With CSS, a color is most often specified by:
a HEX value - like "#ff0000"
an RGB value - like "rgb(255,0,0)"
a color name - like "red"
body {
background-color: #b0c4de;
}
Background Image
body {
background-image: url("paper.gif");
}
Background-repeat-
sets the background image position
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
Two background images
body {
background-image: url("img_tree.gif"), url("img_flwr.gif");
background-color: #cccccc;
}
Background Position
background-position: left top|left center|left bottom|right top|right center|right
bottom|center top|center center|center bottom|x% y% (The right bottom corner is
100% 100%)|xpos ypos(0px 0px)|Initial|inherit;
Body{
Background-position : left top;
}
If you only specify one keyword, the other value will be "center“.
Background Attachment
background-attachment: scroll|fixed|local|initial|inherit;
TEXT FORMATTING
Text Color
The color property is used to set the color of the text. With CSS, a color is most often
specified by:
color: color|initial|inherit;
body {
color: blue;
}
h1 {
color: #00ff00;
}
Value Description
color Specifies the text color.
initial Sets this property to its default
value.
inherit Inherits this property from its
parent element.
Text Alignment
The text-align property is used to set the horizontal alignment of a text.
Text-align:center|right|left|justify
h1 {
text-align: center;
}
p.date {
text-align: right;
}
p.main {
text-align: justify;
}
Vertical-align Property
vertical-align: baseline|length|sub|super|top|text-top|middle|bottom|text-
bottom|initial|inherit;
baseline Align the baseline of the element with the baseline of the parent element. This is default
length Raises or lower an element by the specified length. Negative values are allowed
% Raises or lower an element in a percent of the "line-height" property. Negative values are allowed
sub Aligns the element as if it was subscript
super Aligns the element as if it was superscript
top The top of the element is aligned with the top of the tallest element on the line
text-top The top of the element is aligned with the top of the parent element's font
middle The element is placed in the middle of the parent element
bottom The bottom of the element is aligned with the lowest element on the line
text-bottom The bottom of the element is aligned with the bottom of the parent element's font
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
img {
vertical-align: text-top;
}
Text Decoration
The text-decoration property is used to set or remove decorations from text.
Text-decoration:none|overline|underline|line-through;
a {
text-decoration: none;
}
h1 {
text-decoration: overline;
}
Text Transformation
The text-transform property is used to specify uppercase and lowercase letters in a
text.
text-transform: none|capitalize|uppercase|lowercase|initial|inherit;
p.class1 {
text-transform: uppercase;
}
h1{
text-transform:lowercase;
}
Text Indentation
The text-indent property is used to specify the indentation of the first line of a text.
text-indent: length|initial|inherit;
p {
text-indent: 50px;
}
It may be both in percentage or in pixels
length Defines a fixed indentation in px, pt, cm, em, etc. Default
value is 0
% Defines the indentation in % of the width of the parent
element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
word-spacing Property
word-spacing: normal|length|initial|inherit;
p {
word-spacing: 30px;
}
Value Description
normal Defines normal space between words . This is default
length Defines an extra space between words in px, pt, cm, em, etc.
Negative values are allowed
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
letter-spacing Property
letter-spacing: normal|length|initial|inherit;
h1 {
letter-spacing: 2px;
}
h2 {
letter-spacing: -3px;
}
Value Description
normal No extra space between characters. This is default
length Defines an extra space between characters (negative values are
allowed)
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
Direction Property
direction: ltr|rtl|initial|inherit ;
div {
direction: rtl;
}
Value Description
ltr The writing direction is left-to-right.
This is default
rtl The writing direction is right-to-left
initial Sets this property to its default
value.
inherit Inherits this property from its
parent element.
Text-shadow Property
text-shadow: h-shadow v-shadow blur-radius color|none|initial|inherit;
h1 {
text-shadow: 2px 2px #ff0000;
}
h-shadow Required. The position of the horizontal shadow. Negative values are
allowed
v-shadow Required. The position of the vertical shadow. Negative values are
allowed
blur-radius Optional. The blur radius. Default value is 0
color Optional. The color of the shadow.
none Default value. No shadow
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
Unicode-bidi Property
unicode-bidi: normal|embed|bidi-override|intitial|inherit;
div {
direction: rtl;
unicode-bidi: bidi-override;
}
Value Description
normal Does not use an additional level of embedding. This is default
embed Creates an additional level of embedding
bidi-override Creates an additional level of embedding. Reordering depends
on the direction property
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
White-space Property
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
p {
white-space: nowrap;
}
Value Description
normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is
default
Nowrap Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The
text continues on the same line until a <br> tag is encountered
Pre Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in
HTML
pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line
breaks
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks
initial Sets this property to its default value.
inherit Inherits this property from its parent element.
CSS Font
"Sans" means without
font: font-style font-variant font-weight font-size/line-height font-
family|caption|icon|menu|message-box|small-caption|status-bar|initial|inherit;
p.ex1 {
font: 15px arial, sans-serif;
}
font-style: normal|italic|oblique|initial|inherit;
Font-style
p.oblique {
font-style: italic
}
Font-variant
font-variant: normal|small-caps|initial|inherit;
p.small {
font-variant: small-caps;
} I/P-FONT-VARIANT: SMALL-CAPS;
O/P-MY NAME IS HEGE REFSNES.
font-weight
font-weight: normal|bold|bolder|lighter|number|initial|inherit;
p.normal {
font-weight: normal;
}
font-size
font-size:medium|xx-small|x-small|small|large|x-large|xx
large|smaller|larger|length|initial|inherit;
h1 {
font-size: 250%;
}
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}
Note-Smaller-Sets the font-size to a smaller size than the parent element
%-Sets the font-size to a percent of the parent element's font size
font-family
font-family: font|initial|inherit;
p {
font-family: Times New Roman;
}
Styling Links
The four links states are:
a:link - a normal, unvisited link
a:visited - a link the user has visited
a:hover - a link when the user’s mouse over it
a:active - a link the moment it is clicked
/* unvisited link */
a:link {
color: #FF0000;
text-decoration: none;
}
/* visited link */
a:visited {
color: #00FF00;
text-decoration: underline;
}
/* mouse over link */
a:hover {
color: #FF00FF;
background-color: #FF704D;
}
/* selected link */
a:active {
color: #0000FF;
}
a:hover MUST come after a:link and a:visited
a:active MUST come after a:hover
List
In HTML, there are two types of lists:
unordered lists (<ul>) - the list items are marked with bullets
ordered lists (<ol>) - the list items are marked with numbers or letters
list-style: list-style-type list-style-position list-style-image|initial|inherit;
list-style-type: disc|circle|decimal|decimal-leading-zero|lower-alpha|lower-latin|
lower-roman|none|square|upper-alpha;
list-style-position: inside|outside|initial|inherit;
list-style-image: none|url|initial|inherit;
ul {
list-style-image: url('sqpurple.gif');
}
Table
Table Borders
table, th, td {
border: 1px solid black;
}
Collapse border
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
Table Width and Height
table {
width: 100%;
}
th {
height: 50px;
}
Horizontal Text Alignment
th {
text-align: left;
}
Vertical Text Alignment
td {
height: 50px;
vertical-align: bottom;
}
Table Padding
td {
padding: 15px;
}
Table Color
th {
background-color: green;
color: white;
}
div {
width: 300px;
padding: 25px;
border: 25px solid navy;
margin: 25px;
}
CSS Box Model
Padding
padding: 25px 50px 75px 100px;
top padding is 25px
right padding is 50px
bottom padding is 75px
left padding is 100px
padding: 25px 50px 75px;
top padding is 25px
right and left paddings are 50px
bottom padding is 75px
padding: 25px 50px;
top and bottom paddings are 25px
right and left paddings are 50px
padding: 25px;
all four paddings are 25px
padding-top: 25px;
padding-right: 50px;
padding-bottom: 25px;
padding-left: 50px;
Length may be in percentage, pixels, pt, em.
Margin
The margin property can have from one to four values. (same as padding).
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 50px;
Float and Clear
Clear
used to control the behavior of
floating elements
Clear property specifies on which
sides of an element floating
elements are not allowed to float.
div {
clear: left;
}
Float
used to wrap text around images.
img {
float: right;
margin: 0 0 10px 10px;
}
p {
max-height: 10px;
background-color: yellow;
}
p {
min-height: 2px;
background-color: yellow;
}
Max height of p must be <=10;
Min height of p must be >=2;
CSS Dimension
Display and Visibility
Hiding an Element - display:none or visibility:hidden
h1.hidden {
visibility: hidden;
}
h1.hidden {
display: none;
}
Visibility : hidden hides an element, but it will still take up the same space as
before. The element will be hidden, but still affect the layout.
Display : none hides an element, and it will not take up any space. The element
will be hidden, and the page will be displayed as if the element is not there.
Block and Inline Elements
Examples of block elements (has a line break before and after it):
<h1>
<p>
<li>
<div>
Examples of inline elements (does not force line breaks):
<span>
<a>
Changing How an Element is Displayed
li {
display: inline;
}
span {
display: block;
}
Positioning
Static Positioning
(by default)
Fixed Positioning
will not move even if the window is scrolled
Relative Positioning
• positioned relative to its normal position
• Relatively positioned elements are often used as container blocks for absolutely
positioned elements. (do not overlap)
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position: relative;
left: 20px;
}
position: fixed;
position: relative;
Absolute Positioning
• positioned relative to the first parent element that has a position other
than static. If no such element is found, the containing block is <html>
• Absolutely positioned elements can overlap other elements.
h2 {
position: absolute;
left: 100px;
top: 150px;
}
Overlapping Elements
The z-index property specifies the stack order of an element (which element
should be placed in front of, or behind, the others).
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
Outline
Property Description Values
outline Sets all the outline properties in one declaration outline-color
outline-style
outline-width
inherit
outline-color Sets the color of an outline color_name
hex_number
rgb_number
invert
inherit
outline-style Sets the style of an outline none
dotted
dashed
solid
double
groove
ridge
inset
outset
inherit
outline-width Sets the width of an outline thin
medium
thick
length
inherit
References
1. http://www.w3schools.com/css/
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basics
Vu Tran Lam
 

Was ist angesagt? (20)

Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
Complex Values
Complex ValuesComplex Values
Complex Values
 
Haml
HamlHaml
Haml
 
Lecture 11 css_inculsion
Lecture 11 css_inculsionLecture 11 css_inculsion
Lecture 11 css_inculsion
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
 
Beyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsBeyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery Selectors
 
C S S1
C S S1C S S1
C S S1
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Css outlines
Css outlinesCss outlines
Css outlines
 
CSS INHERITANCE
CSS INHERITANCECSS INHERITANCE
CSS INHERITANCE
 
Css 101
Css 101Css 101
Css 101
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Css2
Css2Css2
Css2
 
Css2
Css2Css2
Css2
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Introduction to HAML
Introduction to HAMLIntroduction to HAML
Introduction to HAML
 
How Groovy Helps
How Groovy HelpsHow Groovy Helps
How Groovy Helps
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basics
 

Ähnlich wie basics of css

5th Lecture- WEB ENGINEERING basics.pptx
5th Lecture- WEB ENGINEERING basics.pptx5th Lecture- WEB ENGINEERING basics.pptx
5th Lecture- WEB ENGINEERING basics.pptx
Aasma13
 

Ähnlich wie basics of css (20)

CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
 
CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learner
 
CSS3 Refresher
CSS3 RefresherCSS3 Refresher
CSS3 Refresher
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
5th Lecture- WEB ENGINEERING basics.pptx
5th Lecture- WEB ENGINEERING basics.pptx5th Lecture- WEB ENGINEERING basics.pptx
5th Lecture- WEB ENGINEERING basics.pptx
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
5. Web Technology CSS Advanced
5. Web Technology CSS Advanced 5. Web Technology CSS Advanced
5. Web Technology CSS Advanced
 
Css
CssCss
Css
 
Css
CssCss
Css
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Web - CSS 1.pptx
Web - CSS 1.pptxWeb - CSS 1.pptx
Web - CSS 1.pptx
 
CSS
CSSCSS
CSS
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Css3
Css3Css3
Css3
 
css-ppt.pdf
css-ppt.pdfcss-ppt.pdf
css-ppt.pdf
 
CSS
CSSCSS
CSS
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 

Kürzlich hochgeladen

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

basics of css

  • 2. CSS stands for Cascading Style Sheet. Typical CSS file is a text file with an extention.css and contains a series of commands or rules. These rules tell the HTML how to display. *To create a style sheet, create a file using Notepad or Text Editor and save it as a .css document and start writing the CSS code.
  • 3. CSS Benefits • Separates structure from presentation • Provides advanced control of presentation • Easy maintenance of multiple pages • Faster page loading • Better accessibility for disabled users • Easy to learn
  • 4. “HTML without CSS is like a piece of candy without a pretty wrapper.” Without CSS, HTML elements typically flow from top to bottom of the page and position themselves to the left by default. With CSS help, we can create containers or DIVs to better organize content and make a Web page visually appealing.
  • 5. Attaching a Style Sheet Attach a style sheet to a page by adding the code to the <head> section of the HTML page. There are 3 ways to attach CSS to a page: 1. External Style Sheet: Best used to control styling on multiple pages. <link rel="stylesheet" type="text/css" href="css/styles.css" /> .css file body { background-color: lightblue; } h1 { color: navy; margin-left: 20px; } 2. Internal Style Sheet: Best used to control styling on one page. <style type=“text/css”> h1 {color: red) </style> 3. Inline Style Sheet*: CSS is not attached in the <header> but is used directly within HTML tags. <p style=“color: red”>Some Text</p>
  • 6. CSS Rule Structure A CSS RULE is made up of a selector and a declaration. A declaration consists of property and value. selector {property: value;} declaration body { property: value; } h1 { property: value; } em { property: value; } p { property: value; }
  • 7. Universal Selector The universal selector is an asterisk. matches all element types in the document. *{ } The Type Selector the same rules to several elements. h1, h2, h3 {} The Class Selector < p class=”student” >…… < /p > <div class=“student”>…….</div> ‘ . ‘ is used to denote a class We can use a class selector in one of two ways here. 1)One way is to directly assign the class name ‘student’. By using this, same rules will be applied to all elements whose class name is ‘student’. .student { }
  • 8. 2)We can apply the attributes to specific elements. p.student { text-align: center; color: red; } The ID Selector The id selector works just like a class selector, but works on the value of id attributes #para1 { text-align: center; color: red; }
  • 9. The Border Properties There are three properties of a border you can change: border - color border - style border - width The border - color Property p {border-color:#ff0000;} It may be border - bottom - color border - right - color border - top - color border - left – color The border - width Property p {border-width:4px;} The value of the border - width property cannot be given as a percentage.. It may be thin medium Thick Can also give border - bottom - width border - right - width border - top - width border - left - width
  • 10. The border - style Property p {border-style : solid;} border - bottom - style border - right - style border - top - style border - left - style
  • 11. The padding Property The padding property allows you to specify how much space should appear between the content of an element and its border: td {padding:5px;} padding - bottom padding - top padding - left padding - right
  • 12. Background Color With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red" body { background-color: #b0c4de; } Background Image body { background-image: url("paper.gif"); }
  • 13. Background-repeat- sets the background image position background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit; body { background-image: url("img_tree.png"); background-repeat: no-repeat; } Two background images body { background-image: url("img_tree.gif"), url("img_flwr.gif"); background-color: #cccccc; }
  • 14. Background Position background-position: left top|left center|left bottom|right top|right center|right bottom|center top|center center|center bottom|x% y% (The right bottom corner is 100% 100%)|xpos ypos(0px 0px)|Initial|inherit; Body{ Background-position : left top; } If you only specify one keyword, the other value will be "center“.
  • 16. TEXT FORMATTING Text Color The color property is used to set the color of the text. With CSS, a color is most often specified by: color: color|initial|inherit; body { color: blue; } h1 { color: #00ff00; } Value Description color Specifies the text color. initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 17. Text Alignment The text-align property is used to set the horizontal alignment of a text. Text-align:center|right|left|justify h1 { text-align: center; } p.date { text-align: right; } p.main { text-align: justify; }
  • 18. Vertical-align Property vertical-align: baseline|length|sub|super|top|text-top|middle|bottom|text- bottom|initial|inherit; baseline Align the baseline of the element with the baseline of the parent element. This is default length Raises or lower an element by the specified length. Negative values are allowed % Raises or lower an element in a percent of the "line-height" property. Negative values are allowed sub Aligns the element as if it was subscript super Aligns the element as if it was superscript top The top of the element is aligned with the top of the tallest element on the line text-top The top of the element is aligned with the top of the parent element's font middle The element is placed in the middle of the parent element bottom The bottom of the element is aligned with the lowest element on the line text-bottom The bottom of the element is aligned with the bottom of the parent element's font initial Sets this property to its default value. inherit Inherits this property from its parent element. img { vertical-align: text-top; }
  • 19. Text Decoration The text-decoration property is used to set or remove decorations from text. Text-decoration:none|overline|underline|line-through; a { text-decoration: none; } h1 { text-decoration: overline; }
  • 20. Text Transformation The text-transform property is used to specify uppercase and lowercase letters in a text. text-transform: none|capitalize|uppercase|lowercase|initial|inherit; p.class1 { text-transform: uppercase; } h1{ text-transform:lowercase; }
  • 21. Text Indentation The text-indent property is used to specify the indentation of the first line of a text. text-indent: length|initial|inherit; p { text-indent: 50px; } It may be both in percentage or in pixels length Defines a fixed indentation in px, pt, cm, em, etc. Default value is 0 % Defines the indentation in % of the width of the parent element initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 22. word-spacing Property word-spacing: normal|length|initial|inherit; p { word-spacing: 30px; } Value Description normal Defines normal space between words . This is default length Defines an extra space between words in px, pt, cm, em, etc. Negative values are allowed initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 23. letter-spacing Property letter-spacing: normal|length|initial|inherit; h1 { letter-spacing: 2px; } h2 { letter-spacing: -3px; } Value Description normal No extra space between characters. This is default length Defines an extra space between characters (negative values are allowed) initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 24. Direction Property direction: ltr|rtl|initial|inherit ; div { direction: rtl; } Value Description ltr The writing direction is left-to-right. This is default rtl The writing direction is right-to-left initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 25. Text-shadow Property text-shadow: h-shadow v-shadow blur-radius color|none|initial|inherit; h1 { text-shadow: 2px 2px #ff0000; } h-shadow Required. The position of the horizontal shadow. Negative values are allowed v-shadow Required. The position of the vertical shadow. Negative values are allowed blur-radius Optional. The blur radius. Default value is 0 color Optional. The color of the shadow. none Default value. No shadow initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 26. Unicode-bidi Property unicode-bidi: normal|embed|bidi-override|intitial|inherit; div { direction: rtl; unicode-bidi: bidi-override; } Value Description normal Does not use an additional level of embedding. This is default embed Creates an additional level of embedding bidi-override Creates an additional level of embedding. Reordering depends on the direction property initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 27. White-space Property white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit; p { white-space: nowrap; } Value Description normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default Nowrap Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered Pre Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks initial Sets this property to its default value. inherit Inherits this property from its parent element.
  • 28. CSS Font "Sans" means without font: font-style font-variant font-weight font-size/line-height font- family|caption|icon|menu|message-box|small-caption|status-bar|initial|inherit; p.ex1 { font: 15px arial, sans-serif; }
  • 29. font-style: normal|italic|oblique|initial|inherit; Font-style p.oblique { font-style: italic } Font-variant font-variant: normal|small-caps|initial|inherit; p.small { font-variant: small-caps; } I/P-FONT-VARIANT: SMALL-CAPS; O/P-MY NAME IS HEGE REFSNES.
  • 30. font-weight font-weight: normal|bold|bolder|lighter|number|initial|inherit; p.normal { font-weight: normal; } font-size font-size:medium|xx-small|x-small|small|large|x-large|xx large|smaller|larger|length|initial|inherit; h1 { font-size: 250%; } h1 { font-size: 2.5em; /* 40px/16=2.5em */ } Note-Smaller-Sets the font-size to a smaller size than the parent element %-Sets the font-size to a percent of the parent element's font size
  • 32. Styling Links The four links states are: a:link - a normal, unvisited link a:visited - a link the user has visited a:hover - a link when the user’s mouse over it a:active - a link the moment it is clicked /* unvisited link */ a:link { color: #FF0000; text-decoration: none; } /* visited link */ a:visited { color: #00FF00; text-decoration: underline; } /* mouse over link */ a:hover { color: #FF00FF; background-color: #FF704D; } /* selected link */ a:active { color: #0000FF; } a:hover MUST come after a:link and a:visited a:active MUST come after a:hover
  • 33. List In HTML, there are two types of lists: unordered lists (<ul>) - the list items are marked with bullets ordered lists (<ol>) - the list items are marked with numbers or letters list-style: list-style-type list-style-position list-style-image|initial|inherit; list-style-type: disc|circle|decimal|decimal-leading-zero|lower-alpha|lower-latin| lower-roman|none|square|upper-alpha; list-style-position: inside|outside|initial|inherit; list-style-image: none|url|initial|inherit; ul { list-style-image: url('sqpurple.gif'); }
  • 34. Table Table Borders table, th, td { border: 1px solid black; } Collapse border table { border-collapse: collapse; } table, th, td { border: 1px solid black; } Table Width and Height table { width: 100%; } th { height: 50px; } Horizontal Text Alignment th { text-align: left; } Vertical Text Alignment td { height: 50px; vertical-align: bottom; } Table Padding td { padding: 15px; } Table Color th { background-color: green; color: white; }
  • 35. div { width: 300px; padding: 25px; border: 25px solid navy; margin: 25px; } CSS Box Model
  • 36. Padding padding: 25px 50px 75px 100px; top padding is 25px right padding is 50px bottom padding is 75px left padding is 100px padding: 25px 50px 75px; top padding is 25px right and left paddings are 50px bottom padding is 75px padding: 25px 50px; top and bottom paddings are 25px right and left paddings are 50px padding: 25px; all four paddings are 25px padding-top: 25px; padding-right: 50px; padding-bottom: 25px; padding-left: 50px; Length may be in percentage, pixels, pt, em.
  • 37. Margin The margin property can have from one to four values. (same as padding). margin-top: 100px; margin-bottom: 100px; margin-right: 150px; margin-left: 50px; Float and Clear Clear used to control the behavior of floating elements Clear property specifies on which sides of an element floating elements are not allowed to float. div { clear: left; } Float used to wrap text around images. img { float: right; margin: 0 0 10px 10px; }
  • 38. p { max-height: 10px; background-color: yellow; } p { min-height: 2px; background-color: yellow; } Max height of p must be <=10; Min height of p must be >=2; CSS Dimension
  • 39. Display and Visibility Hiding an Element - display:none or visibility:hidden h1.hidden { visibility: hidden; } h1.hidden { display: none; } Visibility : hidden hides an element, but it will still take up the same space as before. The element will be hidden, but still affect the layout. Display : none hides an element, and it will not take up any space. The element will be hidden, and the page will be displayed as if the element is not there.
  • 40. Block and Inline Elements Examples of block elements (has a line break before and after it): <h1> <p> <li> <div> Examples of inline elements (does not force line breaks): <span> <a> Changing How an Element is Displayed li { display: inline; } span { display: block; }
  • 41. Positioning Static Positioning (by default) Fixed Positioning will not move even if the window is scrolled Relative Positioning • positioned relative to its normal position • Relatively positioned elements are often used as container blocks for absolutely positioned elements. (do not overlap) h2.pos_left { position: relative; left: -20px; } h2.pos_right { position: relative; left: 20px; } position: fixed; position: relative;
  • 42. Absolute Positioning • positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html> • Absolutely positioned elements can overlap other elements. h2 { position: absolute; left: 100px; top: 150px; } Overlapping Elements The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others). img { position: absolute; left: 0px; top: 0px; z-index: -1; }
  • 43. Outline Property Description Values outline Sets all the outline properties in one declaration outline-color outline-style outline-width inherit outline-color Sets the color of an outline color_name hex_number rgb_number invert inherit outline-style Sets the style of an outline none dotted dashed solid double groove ridge inset outset inherit outline-width Sets the width of an outline thin medium thick length inherit