Advertisement
salmancreation

variables and extend scss

Dec 9th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. I also make sure I have a _variables.scss file, mainly for ease of editing, even if I have only a few variables. Remember to import this file at the top of your main SCSS file.
  2. Note: z-index values should get stored in the variable file. By storing them in this file is not only best practice but allows you to create layers.
  3. @extend
  4. @extend can be used with a selector to pass the already defines styles to another selector.
  5. a {
  6. color: rgb(255,212,84);
  7. display: list-item;
  8. text-decoration: none;
  9. }
  10. button {
  11. @extend a;
  12. }
  13. would compile to:
  14. a, button {
  15. color: #ffd454;
  16. display: list-item;
  17. text-decoration: none;
  18. }
  19. Note: @extend will copy all instances of what is being extended, and not just exact matches.
  20. This is best show through the following example:
  21. $yellow-color: rgb(255,212,84);
  22. $blue-color: rgb(66,134,244);
  23. a {
  24. color: $yellow-color;
  25. display: list-item;
  26. text-decoration: none;
  27.  
  28. &:hover {
  29. color: $blue-color;
  30. }
  31.  
  32. &.link {
  33. border: 1px solid $yellow-color;
  34. }
  35. }
  36. div a {
  37. position: relative;
  38. }
  39. button {
  40. @extend a;
  41. }
  42. which will compile to:
  43. a, button {
  44. color: #ffd454;
  45. display: list-item;
  46. text-decoration: none;
  47. }
  48. a:hover, button:hover {
  49. color: #4286f4;
  50. }
  51. a.link, button.link {
  52. border: 1px solid #ffd454;
  53. }
  54. div a, div button {
  55. position: relative;
  56. }
  57. Did you notice our use of variables too?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement