Padding between divs but not before or after

I'm building a table out of divs. Yes, I know I could just use the <table> element but this needs to be responsive and work with screen readers and <table> elements don't do that very well.

My question is how do I modify the code below so that I can include white space between cells but not before or after them?

I could just add margin-right: 5px but then I get a 5px margin to the right of the last element also. I can always add a class like "lastColumn" which removes the margin for the last element but I'm hoping there's a more elegant solution.

CSS: (background colors are just there for debugging purposes)

div.section
{
    min-width: 100%;
    background-color: aliceblue;
}

div.section div.table
{
    display: table;
    width: auto;
    background-color: aliceblue;
    border-spacing: 5px;
}

div.section div.table div.tr
{
    display: table-row;
    width: auto;
    clear: both;

    min-height: 20px;
    background-color: yellow;
}

div.section div.table div.tr div.td
{
    display: table-cell;
    float: left;
    background-color: fuchsia;
}

Open in new window


Markup:

<div class="table">
    <div class="tr">
        <div class="td">
            <asp:TextBox runat="server" ID="txtName" placeholder="Name"></asp:TextBox>
        </div>
        <div class="td">
            <asp:TextBox runat="server" ID="txtValue" placeholder="Value"></asp:TextBox>
        </div>
        <div class="td">
            <asp:TextBox runat="server" ID="txtComment" placeholder="Comment"></asp:TextBox>
        </div>
    </div>
</div>

Open in new window

LVL 22
Russ SuterSenior Software DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
You can use :last-child or :last-of-type
div.tr div.td:not(:last-child) {
    margin-right: 5px;
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Russ SuterSenior Software DeveloperAuthor Commented:
Works like a charm. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.