1

I'm stuck with a spacing problem. Here's the code:

.border {
  border: 1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
  <div class="col-md-4 border">
    <p>.......</p>
  </div>
  <div class="col-md-4 border">
    <p>.......</p>
  </div>
  <div class="col-md-4 border">
    <p>.......</p>
  </div>
</div>

Without the border, it looks find. But add the border, and they touch one another. Looks very ugly. Adding margin-left and right doesn't help. The last column will be dumped on the next row. Compensating the margin with a negative padding doesn't work either.

I'm out of options. What do I need to do to add some space between the columns?

1
  • One solution is to add the border inside the col-md-4 div instead of adding to it. I'm working on a Joomla template. I have to add the code to the Module Class Suffix. I've tried .margin {-10px;} in front of col-md-4, but that doesn't help. Commented Jul 12, 2016 at 4:38

2 Answers 2

1

Apply your rules to the content inside the column, not the column itself/

.border {
    border: 1px solid red;
}

<div class="col-md-4">
    <div class="border">Content>/div>
</div>

Example:

body {
  padding-top: 60px;
}
.border {
  border: 1px solid red;
  padding: 10px;
  background-color: aliceblue;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <p class="border">Hello</p>
    </div>
    <div class="col-md-4">
      <p class="border">Hello</p>
    </div>
    <div class="col-md-4">
      <p class="border">Hello</p>
    </div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

Just remove right border from all element except last one for example

.border:not(:last-child) {
  border-right: none;
}

Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.