Centering Elements in CSS: How to Vertically Align Content Within a div?
asked 223 days ago
0Answers
12Views
I'm struggling with aligning content vertically within a <div>
using CSS. I've tried various methods such as using flexbox and vertical-align
, but haven't been successful yet. Below is an example of what I've attempted so far:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
border: 1px solid #ccc;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
}
.content {
background-color: lightblue;
padding: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<p>This is the content I'm trying to center vertically within the container.</p>
</div>
</div>
</body>
</html>
I'm looking for a solution or guidance on how to achieve vertical centering of the .content
within the .container
using CSS.