Questions
Create a web page to display 3 images which are aligned left, right and center respectively.
Last Updated : 16 Jul 2025
Jul 22
Solution:
<!DOCTYPE html>
<html>
<head>
<title>Image Alignment</title>
<style>
.container {
width: 100%;
text-align: center; /* Center-aligns the container content */
}
img{
height:60px;
width:100px
}
.left {
float: left;
}
.right {
float: right;
}
.center {
display: inline-block; /* Keeps the image centered within the container */
}
</style>
</head>
<body>
<div class="container">
<!-- Image aligned to the left -->
<img src="https://examjila.com/public/assets/images/courses/olevelwebdesigning.png" alt="Left Image" class="left">
<!-- Image aligned to the center -->
<img src="https://examjila.com/public/assets/images/courses/olevelwebdesigning.png" alt="Center Image" class="center">
<!-- Image aligned to the right -->
<img src="https://examjila.com/public/assets/images/courses/olevelwebdesigning.png" alt="Right Image" class="right">
</div>
</body>
</html>
OUTPUT:
Code Explanation:
-
Container Styling (
.container
):text-align: center;
: Centers the inline content (like images) within the container.
-
Image Styling (
img
):height: 60px;
: Sets the height of all images.width: 100px;
: Sets the width of all images.
-
Image Alignment Classes:
.left
:float: left;
: Aligns the image to the left side of the container.
.right
:float: right;
: Aligns the image to the right side of the container.
.center
:display: inline-block;
: Makes the image behave like an inline element, allowing it to be centered within the container.