You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

themes-sass.asciidoc 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ---
  2. title: Syntactically Awesome Stylesheets (Sass)
  3. order: 3
  4. layout: page
  5. ---
  6. [[themes.sass]]
  7. = Syntactically Awesome Stylesheets (Sass)
  8. Vaadin uses Sass for stylesheets. Sass is an extension of CSS3 that adds nested
  9. rules, variables, mixins, selector inheritance, and other features to CSS. Sass
  10. supports two formats for stylesheet: Vaadin themes are written in SCSS (
  11. [filename]#.scss#), which is a superset of CSS3, but Sass also allows a more
  12. concise indented format ( [filename]#.sass#).
  13. Sass can be used in two basic ways in Vaadin applications, either by compiling
  14. SCSS files to CSS or by doing the compilation on the fly. The latter way is
  15. possible if the development mode is enabled for the Vaadin servlet, as described
  16. in
  17. <<../application/application-environment#application.environment.parameters,"Other
  18. Servlet Configuration Parameters">>.
  19. [[themes.sass.overview]]
  20. == Sass Overview
  21. [[themes.sass.overview.variables]]
  22. === Variables
  23. Sass allows defining variables that can be used in the rules.
  24. [source, css]
  25. ----
  26. $textcolor: blue;
  27. .v-button-caption {
  28. color: $textcolor;
  29. }
  30. ----
  31. The above rule would be compiled to CSS as:
  32. [source, css]
  33. ----
  34. .v-button-caption {
  35. color: blue;
  36. }
  37. ----
  38. Also mixins can have variables as parameters, as explained later.
  39. [[themes.sass.overview.nesting]]
  40. === Nesting
  41. Sass supports nested rules, which are compiled into inside-selectors. For
  42. example:
  43. [source, css]
  44. ----
  45. .v-app {
  46. background: yellow;
  47. .mybutton {
  48. font-style: italic;
  49. .v-button-caption {
  50. color: blue;
  51. }
  52. }
  53. }
  54. ----
  55. is compiled as:
  56. [source, css]
  57. ----
  58. .v-app {
  59. background: yellow;
  60. }
  61. .v-app .mybutton {
  62. font-style: italic;
  63. }
  64. .v-app .mybutton .v-button-caption {
  65. color: blue;
  66. }
  67. ----
  68. [[themes.sass.overview.mixins]]
  69. === Mixins
  70. Mixins are rules that can be included in other rules. You define a mixin rule by
  71. prefixing it with the [literal]#++@mixin++# keyword and the name of the mixin.
  72. You can then use [literal]#++@include++# to apply it to another rule. You can
  73. also pass parameters to it, which are handled as local variables in the mixin.
  74. For example:
  75. [source, css]
  76. ----
  77. @mixin mymixin {
  78. background: yellow;
  79. }
  80. @mixin othermixin($param) {
  81. margin: $param;
  82. }
  83. .v-button-caption {
  84. @include mymixin;
  85. @include othermixin(10px);
  86. }
  87. ----
  88. The above SCSS would translated to the following CSS:
  89. [source, css]
  90. ----
  91. .v-button-caption {
  92. background: yellow;
  93. margin: 10px;
  94. }
  95. ----
  96. You can also have nested rules in a mixin, which makes them especially powerful.
  97. Mixing in rules is used when extending Vaadin themes, as described in
  98. <<themes-creating#themes.creating.sass,"Sass
  99. Themes">>.
  100. Vaadin themes are defined as mixins to allow for certain uses, such as different
  101. themes for different portlets in a portal.
  102. [[themes.sass.basic]]
  103. == Sass Basics with Vaadin
  104. We are not going to give in-depth documentation of Sass and refer you to its
  105. excellent documentation at http://sass-lang.com/. In the following, we give just
  106. basic introduction to using it with Vaadin.
  107. You can create a new Sass-based theme with the Eclipse plugin, as described in
  108. <<themes-eclipse#themes.eclipse,"Creating a
  109. Theme in Eclipse">>.