HTML 6
HTML 6
in
CSS
<div> Tag
• The <div> tag defines a division or a section in an HTML
document.
• The <div> element is often used as a container for other
HTML elements to style them with CSS or to perform certain
tasks with JavaScript.
• The <div> element is very often used together with CSS, to
layout a web page.
• By default, browsers always place a line break before and
after the <div> element. However, this can be changed with
CSS.
• Syntax:
<div> Contents and other tags </div>
DIV TAG
Example
A section in a document that will have a light blue background color:
<!DOCTYPE html>
<html>
<body>
<div style="background-color:lightblue">
<h3>This is a heading in a div element</h3>
<p>This is some text in a div element.</p>
</div>
</body>
</html>
<span> tag
• The HTML <span> tag is used for grouping and applying styles to inline
elements.
• There is a difference between the span tag and the div tag. The span tag is
used with inline elements i.e. style parts of the text while the div tag is used
with block-level content.
• Syntax:
<span> Contents and other tags </span>
• Example:
<html>
<head><title> Span Tag </title></head>
<body>
<p>This is a paragraph <span style = "color:red;">
This is a paragraph</span>This is a paragraph</p>
<p><span style = "color:blue;">
This is another paragraph</span></p>
</body>
<html>
Position Property
• The position property specifies the type of positioning
method used for an element .
– Position:static - Default value. Elements render in order, as they
appear in the document flow. Top, left, right, bottom properties will
not work.
– Position: fixed – Elements with position fixed always stays in the
same place even if the page is scrolled. Top, left, right, bottom
properties will work.
– Position: relative - The element is positioned relative to its normal
position, so "left:20px" adds 20 pixels to the element's LEFT position.
– Position: absolute - The element is positioned relative to its first
positioned (not static) ancestor element.
• Elements are then positioned using the top, bottom, left and
right properties.
Example
<!DOCTYPE html>
<html>
<head>
<style>
div.relative {
position: relative;
width: 400px;
height: 200px;
border: 3px solid green;
}
div.absolute {
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid green;
}
</style>
</head>
<body>
<h2>position: absolute;</h2>
<div class="relative">This div element has position: relative;
<div class="absolute">This div element has position: absolute;</div>
</div>
</body>
</html>
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 along with the position property
to create an effect of layers. 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.
z-index property
• When elements are positioned, they can overlap other
elements.
• The z-index property specifies the stack order of an element.
• An element with greater stack order is always in front of an
element with a lower stack order.
• If two positioned elements overlap without a z-index
specified, the element positioned last in html code will be
shown on top.
• z-index only works on positioned elements (position:absolute,
position:relative, or position:fixed).
• Syntax:
z-index:number;
Example
<html>
<head>
</head>
<body>
<div style="background-color:red; width:300px; height:100px;
position:relative; top:10px; left:80px; z-index:2">
</div>