nested.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .. _css_nestedrules:
  2. Nested rules
  3. ============
  4. .. highlight:: scss
  5. Starting with GeoServer 2.10 the CSS modules supports rule nesting, that is,
  6. a child rule can be written among properties of a parent rule.
  7. The nested rules inherits the parent rule selector and properties, adding its
  8. own extra selectors and property overrides.
  9. Each nested rule can be written as normal, however, if other rules or properties
  10. follow, it must be terminated with a semicolon (this char being the separator in the CSS language).
  11. Nesting is a pure syntax improvement, as such it does not actually provide extra
  12. functionality, besides more compact and hopefully readable styles.
  13. This is an example of a CSS style using only cascading to get a different shape,
  14. fill and stroke color for a point symbol in case the ``type`` attribute equals to ``important``::
  15. [@sd < 3000] {
  16. mark: symbol(circle)
  17. }
  18. [@sd < 3000] :mark {
  19. fill: gray;
  20. size: 5
  21. }
  22. [@sd < 3000] [type = 'important'] {
  23. mark: symbol('triangle')
  24. }
  25. [@sd < 3000] [type = 'important'] :mark {
  26. fill: red;
  27. stroke: yellow
  28. }
  29. This second version uses rule nesting getting a more compact expression, putting related symbology
  30. element close by::
  31. [@sd < 3000] {
  32. mark: symbol(circle);
  33. :mark {
  34. fill: gray;
  35. size: 5
  36. };
  37. [type = 'important'] {
  38. mark: symbol(triangle);
  39. :mark {
  40. fill: red;
  41. stroke: yellow
  42. }
  43. }
  44. }