# StyleSheetExtension : how to extend bootstrap classes with LESS

**URL:** <https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313>\
**Category:** Help / Discuss\
**Created:** [August 9, 2024, 8:55am UTC](https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313 "2024-08-09T08:55:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chentao](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@chentao](https://forum.xwiki.org/u/chentao)\
**Post date:** [August 9, 2024, 8:55am UTC](https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313/1 "2024-08-09T08:55:46Z")

</div>

I created an `XWiki.StyleSheetExtension` object with the following LESS code, which works just fine. Applying `myClass` to an element does indeed apply the CSS styles defined by the classes `myClass1` and `myClass2` :

```auto
.myClass1 {
  /* some CSS style */
}

.myClass2 {
  /* some more CSS style */
}

.myClass {
  &:extend(.myClass1, .myClass2);
}

```

Now, I’d like to create a class that extends the bootstrap classes `table-bordered`, `table-striped`, `table-condensed` and `table-hover`. Something like :

```auto
.myClass {
  &:extend(.table-bordered, .table-striped, .table-condensed, .table-hover);
}

```

I quite often apply those 4 classes to tables, so I’d like to have a more concise way to do this, e.g. I’d like to have to apply only 1 class (`myClass`) instead of all 4.

But it doesn’t work. I guess LESS doesn’t know where to find those classes (which are defined in `skins/flamingo/less/bootstrap/tables.less`).

Any idea how to make it work ?

---

<div class="post-metadata">

**Author:** ![NorSch](https://forum.xwiki.org/user_avatar/forum.xwiki.org/norsch/32/3116_2.png) [@NorSch](https://forum.xwiki.org/u/NorSch)\
**Post date:** [August 9, 2024, 2:08pm UTC](https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313/2 "2024-08-09T14:08:07Z")

</div>

I think that is not possible.  
But with Javascript I think you can do the following:

First delete a style expression (or simple a class) - regardless of where it was defined from.

This can be done by something like

```auto
       function deleteCSS(selektor) {
        console.log("seachCSS: selektor=",selektor);
          var rules = {};
          for (var i = 0; i < document.styleSheets.length; ++i) {
              var cssRules = document.styleSheets[i].cssRules;
              for (var j = 0; j < cssRules.length; ++j)
                  if (cssRules[j]) {
                      if (cssRules[j].selectorText) {
                          var sel = cssRules[j].selectorText.toString();
                          if (sel == selektor) {
                              console.log(" **************************** rule to delete found, old: ", document.styleSheets[i].cssRules[j]);
                              document.styleSheets[i].deleteRule(j);
                              return
                          }
                      }
                  }
          }
          return 
       }

```

and redefine the rule.

---

<div class="post-metadata">

**Author:** ![chentao](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@chentao](https://forum.xwiki.org/u/chentao)\
**Post date:** [August 10, 2024, 5:22am UTC](https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313/3 "2024-08-10T05:22:24Z")

</div>

> [@NorSch](#):
>
> I think that is not possible.

So, basically that means that LESS `&:extend()` function can only extend classes defined within the same `StyleSheetExtension`.

---

<div class="post-metadata">

**Author:** ![chentao](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@chentao](https://forum.xwiki.org/u/chentao)\
**Post date:** [August 11, 2024, 9:25am UTC](https://forum.xwiki.org/t/stylesheetextension-how-to-extend-bootstrap-classes-with-less/15313/4 "2024-08-11T09:25:13Z")

</div>

Answering my own question.  
In fact `&:extend()` isn’t necessary at all. After a few trials and errors, I managed to achieve my goal in a very simple way, using mixins :

```auto
.myClass {
  .table-bordered();
  .table-striped();
  .table-condensed();
  .table-hover();
}

```

Applying `myClass` to a table now applies all 4 bootstrap classes at once. Easy !
