wdd unit 3
wdd unit 3
Importance of CSS
CSS defines HOW HTML elements are to be displayed.
Styles are normally saved in external .css files. External style sheets enable you
to change theappearance and layout of all the pages in a Web site, just by editing one
single file.
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
#para1
{ text-align:center; color:red; }
R. SENTHIL BABU 1
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
3.2 Explain different ways to write the CSS. / Explain CSS with all types. / Enlist
and explain methods of using CSS in web page.
There are three ways of inserting a style sheet:
o External style sheet
o Internal/Embedded style sheet
o Inline style
1. External Style Sheet
o When using CSS it is preferable to keep the CSS separate from your HTML.
o Placing CSS in a separate file allows the web designer to completely
differentiate betweencontent (HTML) and design (CSS).
o External CSS is a file that contains only CSS code and is saved with a ".css" file
extension.
o This CSS file is then referenced in your HTML using the <link> instead of <style>.
File Creation
o Open up notepad.exe, or any other plain text editor and type the following CSS code.
body{ background-color: gray;} p { color: blue; }h3{ color:
white; }
o Save the file as a CSS (.css) file.
o Name the file "test.css" (without the quotes). Now create a new HTML file and
fill it withthe following code.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<h3> A White Header </h3>
<p> This paragraph has a blue font.
The background color of this page is gray because we changed it with CSS!
</p>
</body></html>
R. SENTHIL BABU 2
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
2. Internal/Embedded CSS
o This type of CSS is only for Single Page.
o When using internal CSS, we must add a new tag, <style>, inside the
<head> tag. TheHTML code below contains an example of <style>'s usage.
<html><head>
<style type="text/css"></style>
</head><body>
<p>Your page's content!</p></body>
</html>
3. Inline CSS
o It is possible to place CSS right in your HTML code, and this method of
CSS usage is referred to as inline css.
o Inline CSS has the highest priority out of external, internal, and inline CSS.
o This means that you can override styles that are defined in external or
internal by usinginline CSS.
o If you want to add a style inside an HTML element all you have to do is specify
the desiredCSS properties with the style HTML attribute.
<html><head>
<link rel="stylesheet" type="text/css" href="test.css" /></head>
<body>
<p style="background: blue; color: white;">A new background andfont
color with inline CSS</p></body>
</html>
R. SENTHIL BABU 3
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
R. SENTHIL BABU 4
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
p { font-variant: small-caps; }}
R. SENTHIL BABU 5
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
2. Text Indent
o The text-indentation property is used to specify the indentation of the first line of a
text.
p { text-indent: 20px; } h5 { text-indent: 30%; }
3. Text Align
o The text-align property is used to set the horizontal alignment of a text.
p { text-align: right;
} h5{ text-align:
justify; }
4. Text Transform
o The text-transform property is used to specify uppercase and lowercase letters in a
text.
p { text-transform: capitalize; } h5{ text-transform: uppercase; }
R. SENTHIL BABU 6
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
The box model allows us to place a border around elements and space elements in
relation to otherelements.
The image below illustrates the box model:
R. SENTHIL BABU 7
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
Value Descriptions
auto The browser calculates a margin
length Specifies a margin in px, pt, cm, etc. Default value is
0px
% Specifies a margin in percent of the width of the
containing element
inherit Specifies that the margin should be inherited from
the parent element
R. SENTHIL BABU 8
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
2. Border Width
o The border-width property is used to set the width of the border.
3. Border Color
o The border-color property is used to set the color of the border.
o Border colors can be any color defined by RGB, hexadecimal, or key terms.
Below is anexample of each of these types.
4. Border: border-(direction)
o If you would like to place a border on only one side of an HTML element, or
maybe have a unique look for each side of the border, then use border-
(direction).
o The direction choices are of course: top, right, bottom, and left. CSS allows
you to treateach side of a border separately from the other three sides.
o Each side can have its own color, width, and style set, as shown below.
p { border-bottom-style: dashed ; border-bottom-color: yellow; border-bottom-
width: 5px; }h4 { border-top-style: double; border-top-color: purple; border-top-
width: thick; }
ol { list-style-type: upper-
roman; }ul { list-style-type:
circle; }
R. SENTHIL BABU 9
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
ul { list-style-image:
url("listArrow.gif"); } ol { list-style-
image: url("listArrow2.gif"); }
3. CSS List Position
o With Specify that the the list-item markers should appear inside the content
flow (resultsin an extra indentation)
ul { list-style-position:
inside; } ol { list-style-
position: outside; }
Note: "Outside" is actually the default setting for indentation.
R. SENTHIL BABU 10
III, I WEB DESIGN AND DEVELOPMENT – UNIT III
R. SENTHIL BABU 11
III-I, Web Design & Development- UNIT_I
<body>
<img src="sunset.gif" class="floatLeft"><p>The images are contained with...</p>
<img src="sunset.gif" class="floatRight"><p>This second paragraph has an...</p>
</body>
Introduction to CSS3
CSS3 is the latest standard for CSS.
CSS3 is completely backwards-compatible with earlier versions of CSS.
CSS3 has been split into "modules". It contains the "old CSS specification" (which has been
split into smaller pieces). In addition, new modules are added.
CSS3 Transitions are a presentational effect which allow property changes in CSS values,
such as those that may be defined to occur on :hover or :focus, to occur smoothly over a
specified duration – rather than happening instantaneously as is the normal behaviour.
Transition effects can be applied to a wide variety of CSS properties, including background-
color, width, height, opacity, and many more.
Some of the most important CSS3 modules are:
o Selectors
o Box Model
o Backgrounds and Borders
o Image Values and Replaced Content
o Text Effects
o 2D/3D Transformations
o Animations
o Multiple Column Layout
o User Interface
R. SENTHIL BABU 12