To align three div elements (left, center, and right) inside a parent div, you can use CSS Grid. Here’s how to achieve it using css.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Align Divs</title>
<style>
.container {
display: grid;
grid-template-columns: 1fr auto 1fr; /* Left and right take available space */
width: 100%; /* Adjust width as needed */
border: 1px solid #ccc; /* Optional for visualization */
align-items: center; /* Center vertically if needed */
}
.left, .center, .right {
padding: 10px; /* Optional for spacing */
}
.center {
text-align: center; /* Center the text inside the center div */
}
</style>
</head>
<body>
<div class="container">
<div class="left">Left</div>
<div class="center">Center</div>
<div class="right">Right</div>
</div>
</body>
</html>