Wdtmodule-2 Parta
Wdtmodule-2 Parta
Positioning
Elements, Floating Element
1. Flexbox:
Flexbox (Flexible Box Layout) is a one-dimensional layout method
for laying out items in rows or columns. It provides a more ef cient
and predictable way to distribute space and align items within a
container.
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
.item {
flex: 1;
}
1. Flexbox:
Flexbox (Flexible Box Layout) is a one-dimensional layout method
for laying out items in rows or columns. It provides a more ef cient
and predictable way to distribute space and align items within a
container.
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-template-rows: auto;
gap: 10px;
}
.item {
grid-column: span 2;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.item {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
4. Multi-Column Layout:
The multicol property allows you to create multi-column layouts,
where content ows into multiple columns within a container.
fl
.container {
column-count: 3;
column-gap: 20px;
}
5.Normal Flow:
In the normal ow, elements are laid out one after another in the
order they appear in the HTML document. The ow can be either
horizontal (left to right) or vertical (top to bottom), depending on the
elements.
6. Positioning:
Positioning allows you to control the exact placement of an element
relative to its containing element or the viewport. The position
property is used for this purpose.
Static:
• Default value.
• Elements are positioned according to the normal ow of the
document.
• The top, right, bottom, and left properties have no effect.
Relative:
• The element is positioned relative to its normal position in the
document ow.
• The top, right, bottom, and left properties can be used to
offset the element from its normal position.
Absolute:
• The element is removed from the normal document ow, and
its position is relative to its nearest positioned ancestor.
fl
fl
fl
fl
fl
• If there is no positioned ancestor, it is positioned relative to the
initial containing block (usually the <html> element).
• The top, right, bottom, and left properties are used to position
the element.
Fixed:
• The element is removed from the normal document ow and
positioned relative to the viewport (the browser window).
• It remains xed even when the page is scrolled.
• The top, right, bottom, and left properties are used to
position the element
Sticky:
• The element is treated as relative positioned until it crosses
a speci ed point, then it is treated as fixed positioned.
• The top, right, bottom, and left properties are used to
specify the "sticking" point.
Example:
/* Positioning Example */
.positioned-element {
position: relative;
top: 20px;
left: 30px;
border: 1px solid #ccc;
padding: 10px;
}
7. Floating Elements:
Floating elements allows text and inline elements to wrap around
them. Floated elements are taken out of the normal ow and
positioned to the left or right of their containing element.
Example:
/* Floating Example */
.float-left {
float: left;
width: 150px;
fi
fi
fl
fl
margin: 10px;
}
.float-right {
float: right;
width: 150px;
margin: 10px;
}
8. Canvas
<!DOCTYPE html>
<head>
<title>Canvas Example</title>
<style>
canvas {
border: 1px solid #000;
}
</style>
</head>
<body>
<script>
// Get the canvas element
var canvas = document.getElementById('myCanvas');
// Draw a rectangle
context.fillStyle = 'lightblue';
context.fillRect(50, 50, 100, 50);
// Draw a circle
context.beginPath();
context.arc(300, 100, 30, 0, 2 * Math.PI, false);
context.fillStyle = 'lightgreen';
context.fill();
context.lineWidth = 2;
context.strokeStyle = '#003300';
context.stroke();
</script>
</body>
</html>
Here is context.arc() signature:
arc(x, y, radius, startAngle, endAngle, anticlockwise)
The x and y values de ne the center of our circle, and the radius
will be the radius of the circle upon which our arc will be drawn.
startAngle and endAngle are in radians, not degrees.
anticlockwise is a true or false value that de nes the direction of
the arc.
In this example:
9. Video
<!DOCTYPE html>
<html lang="en">
<head>
<title>Video Example</title>
</head>
<body>
</body>
fi
fi
fi
fi
fi
</html>