I am working with flex
in Tailwind CSS and I have content that’s not being aligned correctly.
<div class="flex flex-col space-y-4 p-2 w-full">
<div class="flex space-x-2">
<p class="w-1/4 text-sm"> python </p>
<div class="h-4 w-1/2 rounded-md mt-1 bg-green-400" style="width: 65%;"></div>
<p class="w-1/4 text-sm"> 65 </p>
</div>
<div class="flex space-x-2">
<p class="w-1/4 text-sm"> html </p>
<div class="h-4 w-1/2 rounded-md mt-1 bg-green-400" style="width: 100%;"></div>
<p class="w-1/4 text-sm"> 100 </p>
</div>
</div>
The HTML is rending like this:
As you see in the graph, the first green line aligns in the center, but I want it to align to the left.
I tried many ways, adding justify-start
, center-start
, etc., but nothing has worked.
2
Answers
with css you can apply at your field
I would just wrap the bar and the value in another
flex
to keep them together. For example:The
flex-1
on the value will eat up the rest of the space on that row so that the value sticks to the end of the bar.Working example here: https://play.tailwindcss.com/M9xW90axaY