tailwind-css

How to add gutters to a flex row


I'm new to tailwind and more familiar with frameworks such as Foundation and Bootstrap. My understanding of tailwind is that it is a utility based framework and structured in such a way that the developer shouldn't need to write any custom CSS for the vast majority of situations. I am a full stack developer with nearing 10 years' experience. It shouldn't be this hard for me to transition to a new framework.

My issue is giving the following markup, tailwind just doesn't work. I'm assuming that the issue here is my understanding of tailwind, but that would indicate a significant shortfall in their documentation.

<div class="flex flex-row flex-wrap space-x-4">
    <div class="w-full lg:w-7/12">
    </div>
    <div class="w-full lg:w-5/12">
    </div>
</div>

This results in the right hand column wrapping to a new line. This should not be the default behavoiur, surely??

If I were to use Foundation, the following markup would suffice and more importantly would work:

<div class="grid-x grid-margin-x">
    <div class="large-7 cell">
    </div>
    <div class="large-5 cell">
    </div>
</div>

The resultant layout should be like this for large screens and should stack on mobile.

Desired layout

People of the internet: tell me where I'm going wrong...


Solution

  • This results in the right hand column wrapping to a new line. This should not be the default behavoiur, surely??

    The flex-wrap class applies flex-wrap: wrap which allows elements to flow to a new line when there isn't enough space along the flex axis, in this case, the horizontal axis.

    At the lg breakpoint, we have two <div> elements, with width: 58.333333% (from lg:w-7/12) and width: 41.666667% (from lg:w-5/12). We then also have margin-left: 1rem on the second <div> element from the parent space-x-4. This means that the overall horizontal space taken up by both <div> elements in total is 100% + 1rem which is greater than the available horizontal space of 100% and thus the elements wrap.

    To have the elements not wrap, you could: