Chapter 3
Chapter 3
Chapter 3
1 What is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 The Box
Model 6 CSS Text
Styling
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Section 1 of 6
WHAT IS CSS?
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
What is CSS?
You be styling soon
CSS Syntax
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
CSS Syntax
Rules, properties, values, declarations
syntax
selector { property: value; property2: value2; } rule
declaration block
selector
em { color: red; }
• Each declaration is
declaration block
terminated with a
semicolon. selector
em { color: red; }
thinking of selectors is
syntax
selector { property: value; property2: value2; } rule
by the browser to
declaration
em { color: red; }
selector { property: value; property2: value2; } rule
selector
em { color: red; }
location of styles
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Actually there are three …
Different types of style sheet
SELECTORS
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Selectors
Things that make your life easier
declaration
declaration block
selector
em { color: red; }
property value
p {
margin: 5px 0 10px 0;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
<div>
<p class="first">By Susan on <time>October 1, 2012</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
.first {
font-style: italic;
color: brown;
}
<div>
<p>By Susan on <time>October 1, 2012</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
#latestComment {
font-style: italic;
color: brown;
}
<div>
#main div p:first-child { <p>By Susan on <time>October 1, 2012</time></p>
color: green; <p>I love Central Park.</p>
} </div>
<hr/>
</div>
<footer>
<ul>
<li><a href="#">Home</a> | </li>
<li><a href="#">Browse</a> | </li>
</ul>
</footer>
</body>
background-attachment Specifies whether the background image scrolls with the document (default) or
remains fixed. Possible values are: fixed, scroll.
background-image Specifies the background image (which is generally a jpeg, gif, or png file) for
the element. Note that the URL is relative to the CSS file and not the HTML.
CSS3 introduced the ability to specify multiple background images.
background-position Specifies where on the element the background image will be placed. Some
possible values include: bottom, center, left, and right. You can also supply a
pixel or percentage numeric position value as well. When supplying a numeric
value, you must supply a horizontal/vertical pair; this value indicates its
distance from the top left corner of the element.
background-repeat Determines whether the background image will be repeated. This is a common
technique for creating a tiled background (it is in fact the default behavior).
Possible values are: repeat, repeat-x, repeat-y, and no-repeat.
background-size New to CSS3, this property lets you modify the size of the background image.
background-image: url(../images/backgrounds/body-background-tile.gif);
background-repeat: repeat;
300px
body {
background: white url(../images/backgrounds/body-background-tile.gif) no-repeat;
background-position: 300px 50px;
}
border-style Specifies the line type of the border. Possible values are: solid,
dotted, dashed, double, groove, ridge, inset, and outset.
border-width The width of the border in a unit (but not percents). A variety of
keywords (thin, medium, etc) are also supported.
border-color: red green orange blue; /* sets all four sides differently
*/
When using this multiple values shortcut, they are applied in clockwise order starting at the top.
Thus the order is: top right bottom left.
TRBL (Trouble)
top
border-color: top right bottom left;
left right
border-color: red green orange blue;
bottom
p {
border: solid 1pt red;
margin: 30px;
padding: 0;
}
p {
border: solid 1pt red;
margin: 30px;
padding: 30px;
}
50px
div {
2 90px border: dotted 1pt green;
padding: 0;
50px margin: 90px 20px;
}
50px 5
p {
50px border: solid 1pt red;
padding: 0;
3 90px margin: 50px 20px;
}
If overlapping margins did not collapse, then margin space for
would be 180p (90pixels for the bottom margin of the first <div> +
90 pixels for the top margin of the second <div>), while the
margins and for would be 100px.
Since the width and the height refer to the size of the
content area, by default, the total size of an element is
equal to not only its content area, but also to the sum
of its padding, borders, and margins.
div {
...
box-sizing: border-box; True element width = 10 + 200 + 10 = 220 px
}
True element height = 10 + 100 + 10 = 120 px
p {
background-color: silver;
}
} 100px
p {
background-color: silver;
width: 200px;
height: 100px;
}
overflow: hidden;
overflow: scroll;
overflow: auto;
TEXT STYLING
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Text Properties
Two basic types
Th
Name
This sans-serif
Without
("sans") serif Th
This
In a regular,
This cursive
1 What is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 The Box
Model 6 CSS Text
Styling
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development