Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bottom Border on Bootstrap Row

I am creating a heading for a section of a page using Bootstrap's grid system, like so:

<div class="row">
    <div class="col-sm-10">
        Heading Text
    </div>
    <div class="col-sm-2 text-right">
        <a href="#"><span class="glyphicon glyphicon-pencil"></span></a>
        <a href="#"><span class="glyphicon glyphicon-trash"></span></a>
    </div>
</div>

What I want to do is add a rule - a horizontal line - below the heading row, so that it looks like this (this uses different icons, but don't worry about that): Example

I can achieve this perfectly by adding this code before the closing tag of the div with the .row class:

<div class="col-sm-12">
    <div style='border-bottom:1px solid #ccc;'></div>
</div>

However, this seems cumbersome to add in all over the place, even if I move the styling to the stylesheet. I've obviously been able to achieve the same effect using append in jQuery (though that has caused issues of its own), but what I'd really like is to accomplish this using pure CSS.

Ideally, I'd add a class to the div with the .row class and the adding of the line would be handled by CSS in the style sheet, but I can't figure it out. The main obstacle is that the child divs to the row have padding of 15px left and right, so if I add the bottom border to the parent row div, the line extends beyond the header content at either end.

Is there a way I can accomplish what I want using pure CSS?

like image 518
Philip Stratford Avatar asked Feb 19 '16 12:02

Philip Stratford


People also ask

How do I add a bottom border in Bootstrap?

. border-right : This class adds a border on the right of the element. . border-bottom : This class adds a border on the bottom of the element.

What is Col MD 6 in Bootstrap?

col-sm- (small devices - screen width equal to or greater than 576px) . col-md- (medium devices - screen width equal to or greater than 768px) . col-lg- (large devices - screen width equal to or greater than 992px)

How do you remove rounded corners from Bootstrap?

Just go to http://getbootstrap.com/customize/ Find all "radius" and modify them as you wish. Click "Compile and Download" and enjoy your own version of Bootstrap.


2 Answers

You could do this with a pseudo element with left and right margin to overcome the padding issue:

@import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css";

.row-bordered:after {
  content: "";
  display: block;
  border-bottom: 1px solid #ccc;
  margin: 0 15px;
}
<div class="container">
  <div class="row row-bordered">
    <div class="col-xs-10">
      Heading Text
    </div>
    <div class="col-xs-2 text-right">
      <a href="#"><span class="glyphicon glyphicon-pencil"></span></a>
      <a href="#"><span class="glyphicon glyphicon-trash"></span></a>
    </div>
  </div>
</div>
like image 58
Turnip Avatar answered Oct 21 '22 21:10

Turnip


The solution above longer works in Bootstrap 4 due to switching to Flexbox, but a few modifications fixes it:

.row-bordered {
  position: relative;
}

.row-bordered:after {
  content: "";
  display: block;
  border-bottom: 1px solid #ccc;
  position: absolute;
  bottom: 0;
  left: 15px;
  right: 15px;
}
<div class="row row-bordered">
  <div class="col-sm-10">
    Heading Text
  </div>
  <div class="col-sm-2 text-right">
    <a href="#"><span class="glyphicon glyphicon-pencil"></span></a>
    <a href="#"><span class="glyphicon glyphicon-trash"></span></a>
  </div>
</div>
like image 36
Ben Comroe Avatar answered Oct 21 '22 20:10

Ben Comroe