CSS Float and positioning
CSS float
This is used to move the divisions in different position. Keyword float is used with respective division for this purpose.
<!DOCTYPE html>
<html>
<head>
<title> CSS with Style </title>
<style type = "text/css" >
.red
{
color:red;
}
.large{
font-size:250%;
}
.underline
{
text-decoration:underline;
}
#first-section
{
color:brown;
font-size:150%;
background-color:pink;
width:200px;
float:left;
}
.underlined
{
text-decoration:underline;
font-size:150%;
color:green;
}
#second-section
{
background-color:yellow;
width:200px;
float:right;
}
.clear-font
{
clear:both;
}
</style>
</head>
<body>
<div id= "first-section">
<p> The quick brown fox jumped over the lazy dog.</p>
<p> Wow this is awesome </p>
</div>
<div id= "second-section">
<p class="red"> This is some more text and <span class="underlined"> this text is underlined.</span></p>
<p><h1 class="red"> CSS is cool </h1></p>
</div>
<div class="clear-font">
<p style="color:royalblue ">I want this para beneath</p>
</div>
</body>
</html>
output
The quick brown fox jumped over the lazy dog.
Wow this is awesome
This is some more text and this text is underlined.
CSS is cool
I want this para beneath
Positioning
CSS Layout - The position Property
The position property specifies the type of positioning method used for an element
(static, relative, fixed, absolute or sticky).
The position Property
The position property specifies the type of positioning method used for an element.
There are five different position values:
static
relative
fixed
absolute
sticky
Elements are then positioned using the top, bottom, left, and right properties.
However, these properties will not work unless the position property is set first.
They also work differently depending on the position value.
position: static;
HTML elements are positioned static by default.
Static positioned elements are not affected by the top, bottom, left, and right properties.
An element with position: static; is not positioned in any special way;
it is always positioned according to the normal flow of the page:
position: relative;==> note - self adjusting not forcing
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element
will cause it to be adjusted away from its normal position.
Other content will not be adjusted to fit into any gap left by the element.
position: fixed;
An element with position: fixed; is positioned relative to the viewport,
which means it always stays in the same place even if the page is scrolled.
The top, right, bottom, and left properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been located.
position: absolute;
An element with position: absolute; is positioned relative to the nearest positioned ancestor
instead of positioned relative to the viewport, like fixed).
owever; if an absolute positioned element has no positioned ancestors,
it uses the document body, and moves along with page scrolling.
Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.
position: sticky;
A sticky element toggles between relative and fixed, depending on the scroll position.
It is positioned relative until a given offset position is met in the viewport -
then it "sticks" in place (like position:fixed).
Comments
Post a Comment