0

In Bootstrap 4 I can use text-truncate as a class in an element. Eg:

<span class="text-truncate">Any very long text</span>

What I need now is to use this class text-truncate in a scss file for many objects instead of writing it directly in .html files.

How to?

Can I use something like:

@import "text-truncate" from "bootstrap.scss";

.myBeautifulDiv {
  use text-truncate;
}

This would be great! Is it possible?

2 Answers2

0

Totally possible. Go here (https://getbootstrap.com/docs/4.1/getting-started/download/), click "Download Source", and what you're looking for is probably in the _scss folder.

tmurphree
  • 79
  • 2
  • 11
0

U can create placeholder classes in scss,

Placeholder classe names start with %.They, themselves, will not be included in the the output css files.

But they can be imported into other classes. Check example below.

Just remember to load your bootstrap css first.

 /*In bootstrap file*/
    .text-truncate{
      text-overflow:ellipsis;
      ...
      ...
    }

 /*In your scss file*/

%truncatedtext {  /*This is placeholder class*/
 @extend .text-truncate;  /*This will include/pull the actual bootstrap code*/
}

.class-a {
  @extend %truncatedtext;
  color: #000000;
}

.class-b {
  @extend %truncatedtext;
  color: red;
}

Its output will be

.text-truncate, .class-a, .class-b {
  /*trucate css code*/
}

.class-a {
  color: #000000;
}

.class-b {
  color: red;
}
Gautam Naik
  • 8,990
  • 3
  • 27
  • 42