Unit-2 WT CSS
Unit-2 WT CSS
Introduction of CSS
Advantages
1. The Element selectors
The advantages of CSS are:
A CSS declaration always ends with a semicolon, and
CSS saves time - You can write CSS once and then reuse the declaration groups
same sheet in multiple HTML pages. are surrounded by curly brackets: example -
Pages load faster – Increases Download Speed p {color:red;text-align:center;}
Easy maintenance - To make a global change, all the To make the CSS more readable, you can put one declaration
elements in all the web pages will be updated automatically. on each line,
Superior styles to HTML – It is better look to your HTML like this:
page in comparison to HTML attributes. p
Multiple Device Compatibility - Style sheets allow content {
to be optimized for more than one type of device. color:red;
Global web standards - Now HTML attributes are being text-align:center;
deprecated and it is being recommended to use CSS }
The caption-side captions are presented in the <caption> Odisha State Open University Page 23
element. By default, these are rendered above the table in the
</style>
document. You use the caption-side property to control the
placement of the table caption. <table class="one">
The empty-cells specify whether the border should be <caption>Collapse Border Example</caption>
shown if a cell is empty.
<tr><td class="a"> Cell A Collapse Example</td></tr>
The table-layout allows browsers to speed up the layout of
a table by using the first width properties it comes across for <tr><td class="b"> Cell B Collapse Example</td></tr>
the rest of a column rather than having to load the whole
</table><br />
table before rendering it.
<table class="two">
The order-collapse Property
<caption>Separate Border Example</caption>
This property can have two values collapse and separate. The
following <tr><td class="a"> Cell A Separate Example</td></tr>
example uses both the values: <tr><td class="b"> Cell B Separate Example</td></tr>
<html> </table>
<head> </body>
<Title>This is my inline css page</Title> </html>
This property can have two values collapse and separate. The
</head>
following example uses both the values:
<body>
Collapse Border Example
<style type="text/css">
Cell A Collapse Example
table.one
table.two
Separate Border Example
{border-collapse:separate;}
{
Cell B Separate Example
border-style:dotted;
border-width:3px;
border-color:#000000;
padding: 10px;
an element should look. There are three properties of a border none: No border. (Equivalent of border-width:0;)
you can change:
solid: Border is a single solid line.
The border-color specifies the color of a border.
dotted: Border is a series of dots.
The border-style specifies whether a border should be
solid, dashed line, double line, or one of the other possible dashed: Border is a series of short lines.
values. double: Border is two solid lines
The border-width specifies the width of a border.
CSS Advanced
Setting Position using CSS
CSS helps you to position your HTML element. You can put
any HTML element at whatever location you like. You can
specify whether you want the element positioned relative to
its natural position in the page or absolute based on its parent
element. Now, we will see all the CSS positioning related
properties with
examples.
Relative Positioning
Relative positioning changes the position of the HTML
element relative to where it normally appears. So "left:20"
adds 20 pixels to the element's LEFT position.
You can use two values top and left along with the position
property to move an
Example:
img { float:right; }
property:
Example
may flow along its side (or be prohibited from doing so by Center Align Elements
the property).
To horizontally center a block element (like <div>), use
With CSS float, an element can be pushed to the left or right, margin: auto;
allowing other
Setting the width of the element will prevent it from
elements to wrap around it. Float is very often used for stretching out to the edges of
images, but it is also
its container. The element will then take up the specified
useful when working with layouts. width, and the remaining
A line box is next to a float when there exists a vertical space will be split equally between the two margins:
position that satisfies all
Example:
of these four conditions:
.center
(a) At or below the top of the line box,
{
(b) At or above the bottom of the line box
margin: auto;
(c) Below the top margin edge of the float, and
width: 50%;
(d) Above the bottom margin edge of the float.
border: 3px solid green;
Elements Float
padding: 10px;
Elements are floated horizontally; this means that an element
can only be }
floated left or right, not up or down. A floated element will Center Align Text
move as far to the left
To just center the text inside an element, use text-align:
or right as it can. Usually this means all the way to the left or center;
right of the
Example:
containing element. The elements after the floating element
will flow around it. .center
Style an element when a user mouses over it sites. A set of buttons or images in a row or column that
serves as a control point
Style visited and unvisited links differently
to link the user to sections on a Web site. The navigation bar
Style an element when it gets focus may also be a
Syntax single graphic image with multiple selections.
The syntax of pseudo-classes: Vertical Navigation Bar
selector: pseudo-class To build a vertical navigation bar we only need to style the
<a> elements, in
{
addition to the code above:
property: value;
Example
}
a { display:block; width:60px; }
Anchor Pseudo-classes
Example explained:
Links can be displayed in different ways:
display:block - Displaying the links as block elements
Example
makes the whole
/* unvisited link */
link area clickable (not just the text), and it allows us to
a:link { specify the width
/* selected link */ ul {
padding: 0;
rule below will match all the input elements having a type
attribute with a value of
text:
input[type="text"]
color: #000000;