Introduction To CSS
Introduction To CSS
DEVELOPMENT
<font size=“14px”>
My First Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
My information 1 goes here.
The old </font>
<font size=“14px”>
way: My Second Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
Different information goes here.
</font>
WHY CSS? CONTINUED.
Separate Content from Form
⚫ Content
⚫ Form or Style
.header { font-size:14px;}
.info { font-family: verdana;
font-color: blue;
font-size: 12px; }
WHAT DOES THIS SEPARATION GET US?
Separate Content from Form
⚫ Specify the style once for every instance of that class.
Example: Specify the font once for all text on the HTML page that
you’ve identified as a “header”.
⚫ Can change the style for your entire site by editing only
ONE FILE.
CSS SKINNING
“Skinning” - changing the look of a page or your site
⚫ Selecting an appearance by choosing which stylesheet to use.
Note, the selector for inline CSS is the tag which contains the style
attribute.
<p style=“font-color:red;font-size:10px;”>Content</p>
THREE CSS DEFINITION LOCATIONS
Internal: the <style> markup tag
This way you are simply placing the CSS code within the
<head></head> tags of each (X)HTML file you want to style with the
CSS.
<head> <html><head><style>
<title><title> p { background-color: Red;
<style type=”text/css”> font-family: serif;
CSS Content Goes Here font-color: White; }
</style> </style></head><body>
</head> <p>Content</p>
<body> </body></html>
With this method each (X)HTML file contains the CSS code needed to style
the page. Meaning that any changes you want to make to one page, will
have to be made to all. This method can be good if you need to style only
one page, or if you want different pages to have varying styles.
THREE CSS DEFINITION LOCATIONS
By using an external style sheet, all of your (X)HTML files link to one
CSS file in order to style the pages. This means, that if you need to alter
the design of all your pages, you only need to edit one .css file to make
global changes to your entire website.
CSS SYNTAX: SELECTORS
There are many kinds of selectors and many ways to reference them:
⚫ Type, Class, ID, Pseudo, etc.
<p>Content</p>
<p class=“myinfo”>Content</p>
<div class=“myinfo”>Other content</div>
CASCADING INHERITANCE
Nested elements inherit
the properties from the
its parent
It consists of 4 edges
⚫ Content edge – It comprises of the actual content
Padding: The padding area is the space around the content area and within
the border-box. It can be applied to all sides of the box or to the specific,
selected side(s) - top, right, bottom, and/or left.
Border: The border area surrounds the padding and the content, and can be
applied to all the sides of the box or to selected side(s) - top, right, bottom,
and/or left.
Margin: The margin area consists of space between the border and the
margin. The margin does not possess its own background color and is
completely transparent. It shows the background color of the element, like the
body element.
CSS BOX MODEL
Important: When you set the width and height properties of an element with
CSS, you just set the width and height of the content area. To calculate the full
size of an element, you must also add padding, borders and margins.
Example:
<body>
div {
<h2>Calculate the total width:</h2>
width: 320px;
<img src="k4_big.jpg" width="350" height="263" alt="Klematis">
padding: 10px;
<div>The picture above is 350px wide. The total width of this
border: 5px solid gray;
element is also 350px</div>
margin: 0;
</body>
}
WIDTH AND HEIGHT OF AN ELEMENT
Here is the calculation:
320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
Total element width = width + left padding + right padding + left border + right
border + left margin + right margin
Total element height = height + top padding + bottom padding + top border + bottom
border + top margin + bottom margin
WIDTH AND HEIGHT OF AN ELEMENT
h1 {
text-align: center;
color: red;
} h1, h2, p {
h2 { text-align: center;
text-align: center;
color: red; color: red;
} }
p{
text-align: center;
color: red;
}
SIMPLE CSS SELECTORS
CSS SELECTORS
CSS selectors are used to "find" (or select) the HTML elements you want to style.
A CSS selector can contain more than one simple selector. Between the simple
selectors, we can include a combinator.
Syntax:
The syntax of pseudo-classes:
selector:pseudo-class
{
property: value;
}
CSS PSEUDO-ELEMENTS
What are Pseudo-Elements?
A CSS pseudo-element is used to style specified parts of an element.
Syntax:
The syntax of pseudo-elements:
selector::pseudo-element
{
property: value;
}
CSS ATTRIBUTE SELECTORS
Style HTML Elements With Specific Attributes
It is possible to style HTML elements that have specific attributes or attribute values.
The following example selects all <a> elements with a target attribute:
a[target]
{
background-color: yellow;
}
CSS COLORS
CSS uses color values to specify a color. Typically, these are used to set a color
either for the foreground of an element (i.e., its text) or else for the background of
the element.
They can also be used to affect the color of borders and other decorative effects.
You can specify your color values in various formats. Following table lists all the
possible formats −
CSS BACKGROUNDS
This teaches you how to set backgrounds of various HTML elements. You can set the
following background properties of an element −
The font-weight property is used to increase or decrease how bold or light a font
appears.
The font property is used as shorthand to specify a number of other font properties.
CSS TEXTS
This teaches you how to manipulate text using CSS properties. You can set following
text properties of an element −
The color property is used to set the color of a text.
The direction property is used to set the text direction.
The letter-spacing property is used to add or subtract space between the letters
that make up a word.
The word-spacing property is used to add or subtract space between the words of a
sentence.
The text-indent property is used to indent the text of a paragraph.
The text-align property is used to align the text of a document.
The text-decoration property is used to underline, overline, and strikethrough text.
The text-transform property is used to capitalize text or convert text to uppercase
or lowercase letters.
The white-space property is used to control the flow and formatting of text.
The text-shadow property is used to set the text shadow around a text.
CSS TABLE
This will teach you how to set different properties of an HTML table using CSS.
You can set following properties of a table −
The border-spacing specifies the width that should appear between table cells.
The empty-cells specifies whether the border should be shown if a cell is empty.
The table-layout allows browsers to speed up layout of a table by using the first
width properties it comes across for the rest of a column rather than having to
load the whole table before rendering it.
CSS SCROLLBAR
There may be a case when an element's content might be larger than the amount of space
allocated to it. For example, given width and height properties do not allow enough room to
accommodate the content of the element.
CSS provides a property called overflow which tells the browser what to do if the box's
contents is larger than the box itself. This property can take one of the following values −
CSS BORDER
The border properties allow you to specify how the border of the box representing an element
should look. There are three properties of a border you can change −
The border-color specifies the color of a border.
border-bottom-color changes the color of bottom border.
border-top-color changes the color of top border.
border-left-color changes the color of left border.
border-right-color changes the color of right border.
The border-style specifies whether a border should be solid, dashed line, double line, or one of
the other possible values.
none − No border. solid − Border is a single solid line.
dotted − Series of dots. dashed − Series of short lines.
double − two solid lines. groove − Border carved into the page.
ridge − Opposite of groove. inset − look like it is embedded in the page.
Outset- look like it is coming out of the canvas.
hidden − Same as none, except in terms of border-conflict resolution for table
The border-width specifies the width of a border.
border-bottom-width border-top-width
border-left-width border-right-width
CSS LISTS
Lists are very helpful in conveying a set of either numbered or bullet points. This teaches you
how to control list type, position, style, etc., using CSS. We have the following five CSS
properties, which can be used to control lists −
The list-style-type allows you to control the shape or appearance of the marker.
The list-style-position specifies whether a long point that wraps to a second line should align
with the first line or start underneath the start of the marker.
The list-style-image specifies an image for the marker rather than a bullet point or number.
The list-style-image allows you to specify an image so that you can use your own bullet style.
The marker-offset specifies the distance between a marker and the text in the list.
CSS SELF STUDY CONCEPTS
CSS Margins
CSS Padding
CSS Outline
CSS Dimension
CSS Visibility
CSS Positioning
CSS Layers
border-radius: Use this element for setting four boarder radius property.
border-top-left-radius: Use this element for setting the boarder of top left corner.
border-top-right-radius: Use this element for setting the boarder of top right corner.
border-bottom-right-radius: Use this element for setting the boarder of bottom right corner.
border-bottom-left-radius: Use this element for setting the boarder of bottom left corner.
Syntax:
#rcorners7 {
border-radius: 60px/15px;
background: #FF0000;
padding: 20px;
width: 200px;
height: 150px;
}
CSS3- MULTI COLUMNS
CSS3 supported multi columns to arrange the text as news paper structure. Some of
most common used multi columns properties as shown below −