0

I have many tables and instead of always giving the class %table.table.table-hover.table-condensed.table-responsive.table-bordered can I somehow set it as %table that will take all the other options from application.css.scss?

I tried

.table {
    .table-responsive;
    .table-bordered;
}

, but it shows wrong.

Any ideas?

1
  • How are you including Bootstrap in your Rails application? Via the official gem or some other means? Commented Feb 23, 2016 at 20:28

1 Answer 1

1

@extend looks like the solution to your problem. Add the following to your scss :

table {
  @extend .table, .table-hover, .table-condensed, .table-responsive, .table-bordered
}

Be careful, though : @extend is tricky and doesn't adds the properties from .table, .table-hover, etc to your definition of 'table', but rather adds the content of the block to all the places in your compiled css where any of the other classes are mentioned.

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

4 Comments

Works great, Thank you! & can you tell me how to move a button class to scss? I currently have %td= link_to 'Show', product, class: 'btn btn-mini btn-success glyphicon glyphicon-search'. I tried to put class: 'button1' & scss @extend .btn, .btn-mini, btn-success, .glyphicon, .glyphicon-search, but it did not work. Mb something with spaces?
You're using Bootstrap 2 ? I tried with the Bootstrap 3 equivalent .button1 {@extend .btn, .btn-xs, .btn-success, .glyphicon, .glyphicon-search}, it works fine. Edit you forgot a dot before btn-success, I don't see any other problem.
Works this way! The .btn-mini does not work, so I did without it
Great ! Could you please accept the answer, then ? :)

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.