: Table Row, is to specify the row in the table,
Table Heading and Table Data.
© : Table Data, within the row you create columns by tag. The
table data can consist of lists, images, forms and other element. The TD is
a true container that can hold other HTML elements and more tables.
Example: A Simple table in HTML
A SIMPLE TABLE IN HTML
‘
TEST TABLE
HEADING |
HEADING 2
HEADING 3
CELL 1 42 :: Certificate in Web Designing and Development
CELL 2
CELL 3
CELL 4
CELL 5
CELL 6
The output of Simple table HTML code is shown in figure 7.1
5 ASW TABLEDNHTR x
© D te:7/C:/Documents%20ande%20Setungs/Admnstator/OES'? 6)
‘TEST TABLE
HEADING 1 HEADING 2 HEADING 3
CELI = CELL2. CELL.
CELL4 © CELLS-—CELLS
Figure- 7.1 : A simple Table without border view in browser
Attributes of
> CELLSPACING: used to set the space bétween the cells in a table. It takes
value in pixel. i
> CELLPADDING: used to set the space between the cell data and cell wall
ina table, It takes value in pixel.
v
WIDTH: used to set the width of the table, as either an absolute with in
pixels, or a percentage of the documents width. For example: attributes
A SIMPLE TABLE IN HTML Advanced HTML and CSS :: 143
TEST TABLE
HEADING 1
HEADING 2
HEADING 3
CELL 1
CELL 2
CELL 3
CELL 4
D> CELL 5
CELL 6
The output of attribute code is shown in Fig. 7.2
COLSPAN: Specifies the number of columns the cell can span, The default
COLSPAN for any cell is 1.
Use of Table Attributes
CELL |
Cell Spans 2 Columns
CELL 2
CELL 3 Certificate in Web Designing and Development
CELL4
The output of COLSPAN code is shown in figure 7.2
Figure 7.2 A sample view - COLSPAN
ROWSPAN: Specifies the number of rows the cell can span. The default
ROWSPAN for any cell is 1.
Example: Use of ROWSPAN
re
Use of Table Attributes
2
Cell Spans 2 rows
CELL 2
CELL 3
CELL 4
CELL 5
Nested Tables
‘Advanced HTML and CSS :: 145
‘Nested Tables means making a table inside another table. Since only the TH
and TD tags can hold data, you will have to code a full table inside the TH or
TD tag of another table.
Hint: Code the first table completely then between the and the
tags (or between the pair of TH tags) code another table. The second table
‘must begin and end in the same cel.
Following is the example of using another table and other tags inside a table
cell.
Name
Salary
Ram Kumar
5000
Sheela Agarwal
7000
<1D>
This is another cell
Using list inside this cell
146 3: Certificate in Web Designing and Development
Row 2, Column 1
Row 2, Column 2
This will produce following result:
* This is another cell
© Using list inside this cell]
Fig. 7.3 Nested table
Effect of Nested Tables on Web Pages:
Asingle table on a web page will generally not affect speed of downloading
process. But, the moment you put one table within another table, it gets more
complicated for the browser to render, and so the page loads slowly. And the
more tables nested inside one another, the slower the page will load.
‘Normally, when a page loads, the browser starts at the top of the HTML and
loads it sequentially down the page. However, with nested tables, it has to
find the end of the table before it can display the entire thing,
To avoid the above problem, you can convert nested tables into slightly more
complex single tables by using the rewspan and colspan attributes on your
table cells,
Guidelines for making Accessible Tables
Screen readers read the content of web pages as if there were no HTML tags at
all. They read everything in the order that it appears in the source markup.
Center for Persons with Disabilities at Utah State University in USA suggest
the following guidelines for making HTML table accessible to people with
disabilities.
1. Avoid tables with more than two levels of row and/or column headers
2. Use proportional sizing, rather than absolute sizing. The rule that appliesAdvanced HTML and CSS
to layout tables also applies to data tables. Let the browser window
determine the width of the table whenever possible, to reduce the horizontal
scrolling required for those with low vision.
3. Provide names or titles for data tables using the tag. Tables ought,
to have some sort of title or caption to them, Itis not absolutely necessary
to have caption tags on every data table for the sake of accessibility, but it
is still a good practice.
4, Header Tags: When you use the table header () tag, most browsers
provide the text to become bold and centered, which can be a nice visual
effect, but the tag should only be used in data tables. Do not use it in
Jayout tables because you may confuse screen reader user.
5. Use the simplest possible table configuration. Visually Challenged users
will “see” all the contents from tables. Their screen readers will inform
the number of rows and columns in the table. When they try to navigate
from one area to the other within the table, they may become disoriented.
The rule of thumb here is, the simpler the better.
6. Designate row and column headers using the tag. The very first step
towards creating an accessible data table is to designate row and/or column
headers. This is easy enough to do. In the markup, the tag is used for
table data cells and the tag is used for table header cells.
INTEXT QUESTION 7.
1. Write True and False against the following statments:
(a) WIDTH specifies the height of a cell.
(b) CELLPADDING used to set the space between the cell data and cell ue
wall in a table.
(©) Table in HTML is defined row by row. The tags define a new
row.
7.4 FORMS
Forms are used in HTML for getting inputs from the users. It can be a
registration form, feedback form, order form and so on.
To take appropriate data inputs, form has components like text fields, radio
buttons, check boxes, list boxes and so on. When data entry is complete, the
user submits the form by clicking the submit button on the page. After
submission, the data are sent to server for processing and the processing is
done through CGI Scripts, PHP, ASP, or servlet etc. This CGI scripts resides
at the server side.148 :: Certificate in Web Designing and Development
After the user fills the form and clicks the submit button, the data pass either
through method POST (used to pass large amount of data) or GET (used to
pass small amount of data, passed along with the URL) to the server side.
‘Then the server handles data and performs appropriate action.
Form elements are like text fields, textarea fields, drop-down menus, radio
buttons, checkboxes, etc. which are used to take information from the user.
A simple syntax of using
Most frequently used
‘The result of this code is the following form:
Fig. 7.9: Drop down box
Following is the list of important attributes of :
+ value: The value that is sent to the server if this option is selected.
‘+ selected: Specifies that this option should be the initially selected value
when the page loads.
+ Iabel: An alternative way of labeling options.
Option groups
The tag is used to group related option groups in a drop-down
list.
Ifyou have a long list of options, groups ofrelated options are easier to handle
for a user, It requires a label attribute, the value of which is displayed as a
—_ 4Advanced HTML and CSS
non-selectable pseudo-heading preceding that group in the drop-down list of
visual browsers. Example source code and their output result are given below:
India
China
Pakistan
Frances/OPTION>
Russia
UK
Canada
Mexico
USA
The result of this code is the following form
Fig. 7.10 : Option groups : Label attributes
File Select Boxes
Ifyou want to allow a user to upload a file to your web site from his computer,
you will need to use a file upload box, also known as file select box. This is
also created using the element.156 :: Certificate in Web Designing and Development
Here is an example HTML code for a form with one file select box:
This will produce following result:
This is page 10
Fig. 7.12 : Hidden form controls
Submit and Reset Button
These are special buttons which can be created using
First name:
Last name: -|
Here
There
Limbo
The above example shows that tabbing would jump from “Here” to “Limbo”
to “There”.
Access keys
‘Access keys allow easier navigation by assigning a keyboard shortcut to a
link (which will usually gain focus when the user presses “Alt” or “Ctrl” +
the access key)158 :: Certificate in Web Designing and Development
Some page
For users who do not use pointing devices, this can be a quick way to navigate.
The trouble is that the user may not be knowing what are different access keys
unless these are explicitly stated, although some assistive software will tell
the user about it.
INTEXT QUESTION 7.2
2. Write True or False against following statments:
(a) RADIO is used for attributes.
(6) Drop down menu is not supported in HTML.
(©) Text Input Controls may be used for multi-line input.
(d) End user can see the hidden form controls.
7.7 CASCADING STYLE SHEETS (CSS) - ADVANCED
In the previous lesson Basic HTML & CSS you have learnt the core concepts
ofCSS. In this lesson, you will get attention to some more advanced aspects
ofCSS such as: adding effects to your anchor tags; and positioning of HTML
elements in a web page.
7.7.1 Advantages of CSS
Cascading Style Sheets, generally referred to as CSS, is a simple design
language intended to simplify the process of making web pages presentable,
CSS is created and maintained through a group of working people called as
World Wide Web Consortium or W3C.
CSS is easy to learn and understand, but it provides powerful control over
the presentation ofan HTML document. Most commonly, CSS is combined
with the markup languages HTML or XHTML. The Advantages of CSS are:
© CSS handles the look and feel part of a web page. Using CSS, you can
control the color of the text, the style of fonts, the spacing between
paragraphs, how columns are sized and laid out, what background images
or colors are used, as well as a variety of other effects.
‘¢ CSS saves time : You can write CSS once and then reuse same sheet in
multiple HTML pages. You can define a style for each HTML element and
apply it to as many Web pages as you want.Advanced HTML and CSS
© Pages load faster - If you are using CSS, you do not need to write HTML
tag attributes every time. Just write one CSS rule of a tag and apply to all
the occurrences of that tag.
+ Easy maintenance - To make a global change, simply change the style,
and all elements in all the web pages will be updated automatically.
© Superior styles to HTML - CSS has a much wider array of attributes than
HTML, so you can give far better look to your HTML page in comparison
of HTML attributes.
‘© Multiple device compatibility - Style sheets allow content to be optimized
for more than one type of device. By using the same HTML document,
different versions ofa website can be presented for handheld devices such
as Personal Digital Assistants (PDAs) and cell phones or for printing
© Global web standards - Now HTML attributes are being deprecated and
it is being recommended to use CSS. So its a good idea to start using CSS
in all the HTML pages to make them compatible to future browsers.
Part of CSS rules
Each rule has two parts:
1. a selector that defines the HTML element(s) to which the rule applies
2. a collection of one or more declarations, made up of a property and a
value, which describe the appearance of all the elements that match the
selector
‘Types of CSS
The three types of CSS style declaration are as follows
1. Internal (Embedded) Styles are defined in the section of the
current web page.
Declaration:
2. Inline Styles are defined within the HTML markup of a particular page
element,
Example:
3. External Styles are written in a separate document and then attached to
cone or more web pages.
Example: 160 :: Certificate in Web Designing and Development
7.7.2 CSS Selectors
InCSS, pattern matching rules determine which style rules apply to elements in
the document tree. These pattems called selectors, may range from simple element
names to rich contextual pattems. Ifall conditions in the pattem are true for acertain
element, the selector matches the element.
‘The case-sensitivity of document language element names in selectors depends on
the document language. For example, in HTML, element names are case-
insensitive, but in XML they are case-sensitive.
‘The following table summarizes CSS selector syntax:
Table 7.1 CSS Selectors syntax
Described in
Pattern | Meaning Section
* ‘Matches any element. Universal selector
E Matches any E element (Le.,anelementof | Type selectors
type E). 7
EF Matches any Felement thatis a descendant | Descendant
of an E element. selectors
E>F Matches any F element that isa child of an | Child selectors
element E.
Esfirst-child| Matches element E when Eis the firstchild | pseudo class/
of its parent. Elements
slink Matches element E if Bis the source anchor | Pseudo-class/
E:visited | of ahyperlink of which the targetis not yet | Ejements
visited (:link) or already visited (-visited). ‘
Eaactive
E:hover | Matches E during certain user actions. Pseudo-class/
Esfocus j Elements
E+F Matches any F element immediately ‘Adjacent meleciors
preceded by a sibling element E.
E{foo] Matches any E element with the “foo” | Attribute selectors
attribute set (Whatever the value).
E{foo=” | Matches any E element whose “foo”
warning”] | attribute value is exactly equal to | Attribute selectors
“warning”,
E[foo- ‘Matches any E element whose “foo™
waming"] | attribute value is a list of space-separated |
values, one of which is exactly equal to | Attribute selectors
“warming”.Advanced HTML and CSS :: 161
Eflangi=" | Matches any E element whose “lang”
en”) attribute has a hyphen-separated list of
values beginning (from the left) with “en”.
Attribute selectors
Emyid | Matches any E element with ID equal to | ID selectors
“myid”.
DIV. Language specific. (in HTML, the same a8
warning | DIV{(class~="warning”].) Class selectors
Source: World Wide Web Consortium (W3C) http://www.w3.org/TR/CSS2/
selectorhtml
7.7.3 Selector Syntax
A simple selector is either a type selector or universal selector followed
immediately by zero or more attribute selectors, ID selectors, or pseudo-
classes, in any order. The simple selector matches if all of its components
match.
The terminology used here in CSS 2.1 is different from what is used in CSS3.
For example, a “simple selector” refers to a smaller part of a selector in CSS3
than in CSS 2.1
A selector is a chain of one or more simple selectors separated by
Combinators. Combinators are: white space, “>”, and “+”. White space may
appear between a combinators and the simple selectors around it.
The elements of the document tree that match a selector are called subjects of
the selector. A selector consisting of a single simple selector matches any
element satisfying its requirements. Prepending a simple selector and
Combinator to achain imposes additional matching constraints, so the subjects
of a selector are always a subset of the elements matching the last simple
selector. ”
One pseudo-element may be appended to the last simple selector in a chain,
in which case the style information applies to a subpart of each subject.
7.7.4 Grouping
When several selectors share the same declarations, they may be grouped into
a comma-separated list
In this example, you condense three rules with identical declarations into one.
Thus,
HI { font-family: sans-serif }162 ::
Certificate in Web Designing and Development
H2 { font-family: sans-serif }
H3 { font-family: sans-serif }
is equivalent to:
HI, H2, H3 { font-family: sans-serif }
CSS offers other “shorthand” mechanisms as well, including multiple
declarations and shorthand properties.
7.7.5 Universal Selector
The universal selector, written “*”, matches the name of any element type, It
matches any single element in the document tree.
If the universal selector is not the only component of a simple selector, the
“*” may be omitted. For example:
©. *[lang=fi] and [lang=fr] are equivalent.
© *.warning and .waming are equivalent.
© *#myid and #myid are equivalent. _
7.7.6 Type selectors
A ne selector matches the name of a document language element type. A
ype selector matches every instance of the element type in the document tree.
‘The following rule matches all H1 elements in the document tree:
HI { font-family: sans-serif }
7.7.7 Descendant Selectors oa
‘At times, authors may want selectors to match an element that is the descendant
of another element in the document tree (e.g., “Match those EM elements that
are contained by an Hi element”). Descendant selectors express such a
relationship in a pattern. A descendant selector is made up of two or more
selectors separated by white space. A descendant selector of the form “A 3”
matches when an element is an arbitrary descendant of
some ancestor element a,
For example, consider the following rules:
HI { color: red }
EM { color: red }
Although the intention of these rules is to add emphasis to text by changing.
its color, the effect will be lost in a case such as:Advanced HTML and CSS :: 163
This headline is very important
The following code will change the text color to blue whenever EM occurs
with HI
HI { color: red }
EM { color: red }
HI EM { color: blue }
The third rule will match the EM in the following fragment:
This headline
is very important
The following selector:
DIV*P.
‘matches a P clement that is a grandchild or later descendant of'a DIV element.
Note the white space on either side of the “*” is not part of the universal
‘selector; the white space is a combinator indicating that the DIV must be the
ancestor of some element, and that element must be an ancestor of the P.
‘The selector in the following rule, which combines descendant and attribute
selectors, matches any element that has the “href” attribute set and is inside
a P that is itself inside a DIV:
DIV P *[HREF]
7.7.8 Child Selectors
A child selector matches when an element is the child of some element. A
child selector is made up of two or more selectors separated by “>”.
‘The following rule sets the style of all P elements that are children of BODY:
BODY > P { line-height: 1.3 }
‘The following example combines descendant selectors and child selectors:
DIV OL>LIP
It matches a P element that is a descendant of an LI; the LI element must be
the child of an OL element; the OL element must be a descendant ofa DIV.
Notice that the optional white space around the “>” combinator has been left
out.
7.7.9 Adjacent Sibling Selectors
Adjacent sibling selectors have the following syntax: El + E2, where E2 is164 +: Certificate in Web Designing and Development
the subject of the selector. The selector matches if E1 and E2 share the same
parent in the document tree and El immediately precedes E2, ignoring non-
clement nodes (such as text nodes and comments).
Thus, the following rule states that, when a P element immediately follows a
MATH element, it should not be indented:
MATH + P { text-indent: 0 }
The next example reduces the vertical space separating an H1 and an H2 that
immediately follows it:
Hi + H2 { margin-top: -Smm }
The following rule is similar to the one in the previous example, except that
it adds a class selector. Thus, special formatting occurs only when H1
has class="opener”:
H.opener + H2 { margin-top: -Smm }
7.7.10 Attribute Selectors
CSS allows authors to specify rules that match elements which have certain
attributes defined in the source document.
Matching attributes and attribute values
Attribute selectors may match in four ways:
{ATT]
Match when the element sets the “att” attribute, whatever the value of
the attribute.
[ATT=val]
Match when the element’s “att” attribute value is exactly “val”.
IATT~=val]
Represents an element with the att attribute whose value is a white space-
separated list of words, one of which is exactly “val”. If “val” contains
white space, it will never represent anything (since the words
are separated by spaces). If “val” is the empty string, it will never
represent anything either.
Attribute values must be identifiers or strings. The case-sensitivity of attribute
names and values in selectors depends on the document language.
For example, the following attribute selector matches all H1 elements thatspecify the “title” attribute, whatever its value:
Hiftitle] { color: blue; }
In the following example, the selector matches all SPAN elements whose
“class” attribute has exactly the value “example”:
SPAN{class~example] { color: blue; }
Multiple attribute selectors can be used to refer to several attributes of an
element, or even several times to the same attribute.
Here, the selector matches all SPAN elements whose “hello” attribute has
exactly the value “Cleveland” and whose “goodbye” attribute has exactly the
value “Columbus”:
SPAN[helk
leveland"][goodbye="Columbus"] { color: blue; }
The following selectors illustrate the differences between “=” and “~=”. The
first selector will match, for example, the value “copyright copyleft
copyeditor” for the “rel” attribute. The second selector will only match when
the “href” attribute has the value “http://www.w3.org’”.
Afrel—="copyright"]
Afhref"hetp://www.w3.org/"]
7.7.11 Class Selectors
‘Working with HTML, authors may use the period (.) notation as an alternative
to the ~= notation when representing the class attribute.
Thus, for HTML, div. value and div[class~=value] have the same
meaning. The attribute value must immediately follow the “period” (..).
For example, you can assign style information to all elements
with class-—"pastoral" as follows:
* pastoral { color: green } /* all elements with class~pastoral */
or just
-pastoral { color: green } /* all elements with class~=pastoral */
The following assigns style only to H1 elements with class~="pastoral”:
Hi pastoral { color: green } /* H1 elements with class~=pastoral */
Given these rules, the first H1 instance below would not have green text, while
the second would:166 :: Certificate in Web Designing and Development
Not green/H1>
element
yee
first-line pefirst-line | Selects the first line of every
element .
irst-child pifirst-child | Selects every
elements that is the
first child of its parent
:before prbefore Insert content before every
element
after prafter Insert content after every
element
slang(language) | p:lang(it) Selects every
element with a lang
attribute value starting with “
The syntax of pseudo-classes:
selectorspseudo-class {property:value;}
CSS classes can also be used with pseudo-classes:
selector.class:pseudo-class {property:valu
Link Selector
You can apply what you already learnt in the previous lessons to links (ie.
change colors, fonts, underline, etc). The new point is that CSS allows you to
define these properties differently, depending on whether the link is unvisited,
visited, active, or whether the cursor is on the link. This makes it possible to
add fancy and useful effects to your website. To control these effects you can
use so-called pseudo-classes.
Example Link.css
Select and style unvisited, visited, hover, and active links:
ink ——_{color:green;}
fed {color:green;}
over {color:red;}
tive {color:yellow;} *168 :: Certificate in Web Designing and Development
Use az link and a: visited for unvisited and visited links respectively. Links
that are active have the pseudo-class a: active and a: hover is when the cursor
is on the link.
Example Link.html
Mouse over and click the link:
nios.ac.in
Output in Browser
Fig. 7.14: Sample output for Link.html
Pseudo-class: hover
The pseudo-class :hover is used when the mouse pointer hovers over a link.Advanced HTML and CSS :: 169
This can be used to create interesting effects. For example, if we want our
links to.be yellow and be italicized when the cursor is pointed at them, our
CSS should look like this:
Example, Select and style a link when you mouse over it:
achover
t
background-color:yellow;
font-style: italic;
}
The hover selector can be used on all elements, not only on links.
Example Hover.html
nios.ac.in ;
wikipedia.org
Note: The -hover selector style links on mouse-over.
170 =: Certificate in Web Designing and Development
Output in Browser
Fig, 7.15 : Sample output for hover.html
Navigation Bars
Having easy-to-use navigation is important for any web site. With CSS you
can transform normal HTML menus into good-looking navigation bars.
Navigation Bar = List of Links
A navigation bar needs standard HTML as a base. In below example, source
codes will build the navigation bar from a standard HTML list. A navigation
bar is basically a list of links, so using the and elements make perfect
sense: ‘
Example NaviagtionBar.html x
News
About
A background color is added to the links to show the link area.
Notice that the whole link area is clickable, not just the text.
The above example code:
list-style-type:none - Removes the bullets. A navigation bar does not need list
markers
Setting margins and padding to 0 to remove browser default settings
To build a vertical navigation bar, style elements is used in to the code.
Output in Browser
‘A baceround colori added tothe Eek to show the ak area.
Fig. 7.16 : Sample output for Navigation Bar
Now let’s remove the bullets and the margins and padding from the lis
7.9 CSS FLOAT
With CSS float, an element can be pushed to the left or right, allowing other172 :: Certificate in Web Designing and Development
elements to wrap around it. Float is very often used for images, but itis also
useful when working with layouts.
Elements are floated horizontally; this means that an element can only be
floated left or right, not up or down. A floated element will move as far to the
left or right as it can, Usually this means all the way to the left or right of the
containing element. The elements after the floating element will flow around
it, The elements before the floating element will not be affected. If an image
is floated to the right, following text flows around it, to the left:
Example:
img
c
float:right;
}
Example CSSFloat.html
In the paragraph below, we have added an image with style
float:right . The result is that the image will float to the right in
the paragraph.
National Institute of Open Schooling.
National Institute of Open Schooling...
Output in Browser
Fig. 7.17: Sample output for Float
Turning off Float - Using Clear
Elements after the floating element will flow around it. To avoid this, use the
clear property.The clear property specifies which sides of an element other
floating elements are not allowed. Add a text line into the image gallery, using
the clear property:
Example:
-text_line
{
clear:both;
3
7.10 CLEAR
The clear CSS property specifies whether an element can be next
to floating clements that precede it or must be moved down (cleared) below
them, The clear property applies to both floating and non-floating elements.174 :: Certificate in Web Designing and Development
Property Values
Value Description
left No floating elements allowed on the left side
right No floating elements allowed on the right side
both No floating elements allowed on either the left or the right side
none Default. Allows floating elements on both sides
inherit Specifies that the value of the clear property should be inherited
from the parent element
‘Table 7.3
‘When applied to non-floating blocks, it moves the border edge of the element down
until itis below the margin edge of all relevant floats. This movement (when it
happens) causes margin collapsing not to occur.
When applied to floating elements, it moves the margin edge of the element below
the margin edge of all relevant floats. This affects the position of later floats, since
later floats cannot be positioned higher than earlier ones. The floats that are relevant
tobe cleared are the earlier floats within the same block formatting context.
Example Clear.Html
No floating elements allowed on the left or the right side of a specified paragraph:
This text appear afier clear property.
'95" height="84" />Advanced HTML and CSS :: 175
‘The output of the above code is given below.
fa
‘This text appear afer clear property
This is some text.
Fig. 7.18 : Clear Property
7.11 VISIBILITY
Aproperty called visibility allows you to hide an element from view. You can use
this property alongwith Javascriptto create very complex menu and very complex
webpage layouts,
‘You may choose to use the visibility property to hide error messages that are only
displayed ifthe user needs to see them, or to hide answers to a quiz until the user
selects an option.
Note: Remember that the source code will still contain whatever isin the invisible
paragraph, so you should not use this to hide sensitive information such as credit
card details or passwords.
The visibility property can take the values listed in the table that follows:
‘Table 7.4 : visibility values
Value Description
Visible | The box and its contents are shown to the user.
Hidden | The box and its content are made invisible, although they still
affect the layout of the page.
Collapse | This is for use only with dynamic table columns and row
effects.
Here is the example:
‘This paragraph should be visible in normal way.
This paragraph should not be visible.
176 :: Certificate in Web Designing and Development
This will produce following resul
This paragraph should be visible in normal we
7.12 POSITIONING
CSS helps you to position your HTML element. You can put any HTML
element at whatever location you like. You can also specify whether you want
the element positioned relative to its natural position in the page or absolute
based on its parent element.
‘Now you will leam three type of CSS positioning like Relative, Absolute
and Fixed and their properties with examples:
You can use two values top and left, alongwith position property to move an
HTML element anywhere in HTML document. Here’s a: quick reference when
moving HTML elements in CSS.
© Move Left - Use a negative value for left.
‘© Move Right - Use a positive value for left.
© Move Up - Use a negative value for top.
‘© Move Down - Use a positive value for top.
Note: You can use bottom or right values as well in the same way as top and
left.
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.
Here is the example:
This div has absolute positioning,
This will produce following result:
This div has absolute positionin
Fixed Positioning
Fixed positioning allows you to fix the position of an element to a particular
spot on the page - regardless of scrolling. Specified coordinates will be relative
to the browser window.
Here is the example:
This div has fixed positioning.
Scroll down this page using scrollbar available at right side:
This will produce below output in browser.
Fig. 7.19 : Fixed positioning178 :: Certificate in Web Designing and Development
7.13 CSS LAYERS
CSS gives you opportunity to create layers of various divisions. The CSS
layers refer to applying the z-index property to elements that overlap with each
other. The z-index property is used alongwith position property to create an
effect of ayers. You can specify which element should come on top and which
element should come at bottom.
‘A z-index property can help you to create more complex webpage layouts.
Following is the example which shows how to create layers in CSS.
n:relative;‘Advanced HTML and CS
179
This
ll produce following result:
Fig. 7.20: CSS Layers
7.14 LAYOUTS
In previous sections, you have already learnt the designing of page layouts using
HTML Tables. However you must know CSS also provides plenty of controls for
positioning elements in a document
is pivotalto the future of web documents and will be supported by most
browsers
© CSSismoreexact than tables, allowing your document to be viewed as you
intended, regardless of the browser window.
© Keeping track ofnested tables can be a difficult task,
© CSS rules tend to be well organized, easily read, and easily changed.
CSS also provides table-layout property to make your tables load much faster.
Following is the example:
CSS table layout cell 1
'200">CSS table layout cell 2
CSS table layout cell 3
ixed;width:600px;">
Simple Column Layout
Here are the steps to create a simple Column Layout using CSS:180 :: Certificate in Web Designing and Development
‘Set the margin and padding of the complete document as follows:
Now wewill define a column with yellow color and later we will attach this rule to
a:
Upto this point we willhavea document with yellow body, so lets now define another
division inside level:
Now we will nest one more division inside level! and we will change just
background color:
Finally we use the same technique, nest a level3 division inside level2 to get
the visual layout for the right column:Advanced HTML and CSS ::
‘Complete source code
Final Content goes here...
Final Content goes here...
Final Content goes here...
_This section will expand when you will put more content here:
In similar way you can add top navigation bar or ad bar at the top of the page.
‘This example code will produce following result:
Fig. 7.21 : Simple Column Layout‘Advanced HTML and CSS :: 183
‘The CSS muiti-column layout extends the block layout mode to allow the easy
definition of multiple columns of text. People face problems in reading text if lines
are too long; ifit takes too long for the eyes to move from the end of the one line
to the beginning of the next, they lose track of which line they were on. Therefore,
to make maximumuse ofa large screen, you should have limited-width columns of
text placed side by side, just as newspapers do.
Unfortunately this is impossible to do with CSS and HTML without foreing column
breaks at fixed positions, or severely restricting the markup allowed inthe text, or
using heroic scripting. This limitation is solved by adding new CSS properties to
extend the traditional block layout mode.
Here is an example ofa simple three-column class:
-webkit-column-gap: 20px;
}
Of which you would apply to a block of text like so:
Sample HTML:
‘