Css Basics
Css Basics
declaration
Selectors
}
IDs and Classes
• IDs (#) are unique and can only be used once on the page
• Classes (.) can be used as many times as needed
HTML Code:
<h1 id=“mainHeading”>Names</h1>
<p class=“name”>Joe</p>
CSS Code:
#mainHeading {color: green}
.name {color: red}
Grouping Selectors
Group the same selector with different declarations
together on one line.
h1 {color: black;}
h1 {font-weight: bold;}
h1 {background:
white;}
Example of grouping selectors (both are
correct):
h1 {
color: black;
font-weight: bold;
Grouping Selectors
Group different selectors with the same declaration on
one line.
h1 {color: yellow;}
h2 {color: yellow;}
h3 {color: yellow;}
header
menu main
footer
Typical Web Page (HTML)
Typical HTML Web page is made up of containers (boxes)
or DIVs. Each DIV is assigned an ID or a Class.
<div id=“container”>
<div id=“header”>Insert Title</div>
<div id=“main">content
<div id=“menu”>content</div>
</div>
<div id=“footer”>content</div>
</div>
The Box Model
CSS works on the
box model. A
typical Web page
consists of many
boxes joined
together from top
to bottom. These
boxes can be
stacked, nested,
and can float.
Header
Navigation
Content
Footer
Typical Web Page (CSS)
The CSS file uses the same DIV/ID/Class names as the
HTML and uses them to style the elements.
• Background-color
• Width
• Padding
• Margin
• Border-width
• Border-color
• Border-style
HTML CSS
#content {
background-color: #ccc;
div id=“header”
margin-bottom: 10px;
border: 1px dashed blue;
color: #fff;
width: auto;
}
div id=“content”
div id=“footer”
Common CSS Layout Properties
• Width margin
padding
• Height
• Float
width
• Clear
height
• Border border
• Padding
• Margin
Width & Height
Width and height define the width and height of an element.
div id=“box”
div id=“box3”
div id=“box”
div id=“box”
padding: 10px 10px 10px 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-top: 10px;
Margin (top, right, bottom, left)
Margin is the space outside the text/content and the border. You can use
margin for all around the element or specify each side of the rectangle
separately.
The code could be any of the following:
• White • #ffffff
• Black • #fff
• Blue • #cccf0f3
• Fuchsia HSL( HUE SATURATION LIGHT)
• Gray
• Green
• Lime
• Aqua
Including Images
Properties for working with images include:
• Background-image
• Background-repeat
• Background-position
• Background-attachment
Layering div id=“bg”
li {
background-image:url(flower.jpg);
background-repeat:no-repeat;
}
• repeat
Possible Values > • repeat-x (horizontal)
• repeat-y (vertical)
• no-repeat
Image Positioning left center
top top
The background-position
property positions the image left center right
using either combined bottom bottom bottom
keywords (top, bottom, left,
right, and center); length
values; or percentage values.
The background-
background-position: right top;
/*can also use number values*/
attachment property
fixes or scrolls an
background-attachment: fixed; / image in the browser
*can also use ‘scroll’*/ window. Values
include fixed and scroll.
The Power of Cascade
When multiple styles or style sheets are used, they start to
cascade and sometimes compete with one another due to CSS’s
inheritance feature. Any tag on the page could potentially be
affected by any of the tags surrounded by it.
Great Book
“CSS: The Missing Manual” - by David Sawyer McFarland
CSS Galleries
http://www.cssbeauty.com/gallery/
www.cssdrive.com
http://www.css-website.com
Thank You