question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add border utility classes

See original GitHub issue

For my own projects, I’m using a set of border utility classes, that significantly extend the current number of border utilities. With these classes, you can add or remove borders on any side individually (top, bottom, right, left) and the two axis (x, y) for all breakpoints.

Would you be interested in accepting a feature PR to include this into the main repo? Below are the classes it would add:

.bt # border top
.bb # border bottom
.br # border right
.bl # border left
.by # border y-axis
.bx # border x-axis
.bt-off
.bb-off
.br-off
.bl-off
.by-off
.bx-off
.bt-sm
.bb-sm
.br-sm
.bl-sm
.by-sm
.bx-sm
.bt-sm-off
.bb-sm-off
.br-sm-off
.bl-sm-off
.by-sm-off
.bx-sm-off
# ...and so on and so forth

I initially had used -on and -off suffixes, but decided to remove them in favor of the -0 approach used by bootstrap in other places. The downside is that the shorter, not breakpoint classes become a little too terse to be easily understandable. What do you think?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
andresgalantecommented, Sep 6, 2017

I would’t want to see a class for each CSS property, that’s what I hate about frameworks like atomic CSS or tachyons.

But if you do want to do this, I suggest to use the same naming conventions as border utilities. So .border- instead of .b

0reactions
robsilvacommented, Oct 25, 2017

I really like the naming convention used by the spacing utilities, so I created this mixin to do the same with borders:

/* Border Mixin */

$positions: t r b l;
$sizes: 3;

@mixin borders($size) {
  	@each $x in $positions {
	    @if $x == t {
	    	.b-#{$x}#{$size} { border-top: #{$size}px solid rgba(0,0,0,0.1); }
		} @else if $x == r {
			.b-#{$x}#{$size} { border-right: #{$size}px solid rgba(0,0,0,0.1); }
		} @else if $x == l {
			.b-#{$x}#{$size} { border-left: #{$size}px solid rgba(0,0,0,0.1); }
		} @else if $x == b {
			.b-#{$x}#{$size} { border-bottom: #{$size}px solid rgba(0,0,0,0.1); }
		}
	}
	.b-#{$size} { border: #{$size}px solid rgba(0,0,0,0.1); }
}

@for $i from 1 through $sizes {
	@include borders($i);
}

which generates:

.b-t1 {
  border-top: 1px solid rgba(0, 0, 0, 0.1); }

.b-r1 {
  border-right: 1px solid rgba(0, 0, 0, 0.1); }

.b-b1 {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1); }

.b-l1 {
  border-left: 1px solid rgba(0, 0, 0, 0.1); }

.b-1 {
  border: 1px solid rgba(0, 0, 0, 0.1); }

.b-t2 {
  border-top: 2px solid rgba(0, 0, 0, 0.1); }

.b-r2 {
  border-right: 2px solid rgba(0, 0, 0, 0.1); }

.b-b2 {
  border-bottom: 2px solid rgba(0, 0, 0, 0.1); }

.b-l2 {
  border-left: 2px solid rgba(0, 0, 0, 0.1); }

.b-2 {
  border: 2px solid rgba(0, 0, 0, 0.1); }

.b-t3 {
  border-top: 3px solid rgba(0, 0, 0, 0.1); }

.b-r3 {
  border-right: 3px solid rgba(0, 0, 0, 0.1); }

.b-b3 {
  border-bottom: 3px solid rgba(0, 0, 0, 0.1); }

.b-l3 {
  border-left: 3px solid rgba(0, 0, 0, 0.1); }

.b-3 {
  border: 3px solid rgba(0, 0, 0, 0.1); }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Borders - Bootstrap
Use border utilities to add or remove an element's borders. Choose from all borders or one at a time. Additive.
Read more >
Bootstrap Borders - examples & tutorial
Use border utilities to add or remove an element's borders. Choose from all borders or one at a time. Additive. Additive classes are...
Read more >
Bootstrap 4 Utilities - W3Schools
Bootstrap 4 has a lot of utility/helper classes to quickly style elements without using any CSS code. Borders. Use the border classes to...
Read more >
Borders in bootstrap with examples - GeeksforGeeks
In Bootstrap, there are different classes available to add or remove borders. The classes that are used to add borders are referred as ......
Read more >
Borders - Lightning Design System
Use border utility classes to add borders to elements. Examples#. Top#. This should have a top border. Show Code. <div class="slds-border_top">This should ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found