I’m working on a project where I need to position three elements:
- A number inside a red circle.
- An
<h3>
header aligned on the same row as the number. - A
<p>
element starting directly below the<h3>
header.
here is my code:
<div class="rounded-l-full bg-brightredsuplight md:bg-transparent">
<div class="flex flex-col space-y-4">
<div class="flex items-center space-x-2">
<div class="px-4 py-2 text-white bg-brightred rounded-full md:py-1">
01
</div>
<h3 class="text-base text-verydarkblue font-bold md:mb-4 md:hidden">
Track company wide progress
</h3>
</div>
<p class="text-darkgrayishblue pl-12">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Officiis
voluptatibus ea ab ullam esse animi vel eius sint laboriosam natus
et ex accusamus, at ipsa voluptates! Voluptatem illum molestias eaque!
</p>
</div>
</div>
Currently, the number and h3 are positioned correctly, but the p element starts too far left.
How can I make the p element start exactly where the h3 starts?
Here’s the project link:
Frontend Mentor Challenge
I tried the following approaches to align the p element under the h3 correctly:
Adding Padding or Margin: I used classes like pl-12
and ml-4
to shift the p element.
Wrapping in a Parent Div: I added an extra div to group the h3 and p elements and applied spacing classes to the div.
Adjusting Classes in Containers Above: I tried modifying the space-x-2
and items-center on the container wrapping the number and h3.
Despite these attempts, the p element doesn’t align correctly under the h3. I’m expecting the p text to start exactly where the h3 text starts while keeping the layout intact.
2
Answers
I just wanted to update everyone: The issue was caused by a margin: 0 style applied to the
<p>
element in the main.css file. Once I removed that, everything aligned perfectly, with the<p>
starting below the<h3>
and the number and<h3>
remaining in the same row.Thanks to everyone for the suggestions!
Why misalign the p element though? You can just absolutely position the number relative to the h3, then set a negative left position on it. E.g: