_objects.flag.scss 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* ==========================================================================
  2. #FLAG
  3. ========================================================================== */
  4. /**
  5. * The flag object is a design pattern similar to the media object, however it
  6. * utilises `display: table[-cell];` to give us control over the vertical
  7. * alignments of the text and image.
  8. *
  9. * http://csswizardry.com/2013/05/the-flag-object/
  10. *
  11. * 1. Allows us to control vertical alignments.
  12. * 2. Force the object to be the full width of its parent. Combined with [1],
  13. * this makes the object behave in a quasi-`display: block;` manner.
  14. * 3. Reset inherited `border-spacing` declarations.
  15. */
  16. .o-flag {
  17. display: table; /* [1] */
  18. width: 100%; /* [2] */
  19. border-spacing: 0; /* [3] */
  20. }
  21. /**
  22. * Items within a flag object. There should only ever be one of each.
  23. *
  24. * 1. Default to aligning content to their middles.
  25. */
  26. .o-flag__img,
  27. .o-flag__body {
  28. display: table-cell;
  29. vertical-align: middle; /* [1] */
  30. }
  31. /**
  32. * Flag images have a space between them and the body of the object.
  33. *
  34. * 1. Force `.flag__img` to take up as little space as possible:
  35. * https://pixelsvsbytes.com/2012/02/this-css-layout-grid-is-no-holy-grail/
  36. */
  37. .o-flag__img {
  38. width: 1px; /* [1] */
  39. padding-right: $inuit-global-spacing-unit;
  40. /**
  41. * 1. Fixes problem with images disappearing.
  42. *
  43. * The direct child selector '>' needs to remain in order for nested flag
  44. * objects to not inherit their parent’s formatting. In case the image tag
  45. * is wrapped into another tag, e.g. an anchor for linking reasons, it will
  46. * disappear. In that case try wrapping the whole o-flag__img object into
  47. * an anchor tag.
  48. *
  49. * E.g.:
  50. *
  51. * <a href="/">
  52. * <div class="o-flag__img">
  53. * <img src="./link/to/image.jpg" alt="image alt text">
  54. * </div>
  55. * </a>
  56. */
  57. > img {
  58. max-width: none; /* [1] */
  59. }
  60. }
  61. /**
  62. * The container for the main content of the flag object.
  63. *
  64. * 1. Forces the `.flag__body` to take up all remaining space.
  65. */
  66. .o-flag__body {
  67. width: auto; /* [1] */
  68. &,
  69. > :last-child {
  70. margin-bottom: 0;
  71. }
  72. }
  73. /* Size variants
  74. ========================================================================== */
  75. .o-flag--flush {
  76. > .o-flag__img {
  77. padding-right: 0;
  78. padding-left: 0;
  79. }
  80. }
  81. .o-flag--tiny {
  82. > .o-flag__img {
  83. padding-right: $inuit-global-spacing-unit-tiny;
  84. }
  85. &.o-flag--reverse {
  86. > .o-flag__img {
  87. padding-right: 0;
  88. padding-left: $inuit-global-spacing-unit-tiny;
  89. }
  90. }
  91. }
  92. .o-flag--small {
  93. > .o-flag__img {
  94. padding-right: $inuit-global-spacing-unit-small;
  95. }
  96. &.o-flag--reverse {
  97. > .o-flag__img {
  98. padding-right: 0;
  99. padding-left: $inuit-global-spacing-unit-small;
  100. }
  101. }
  102. }
  103. .o-flag--large {
  104. > .o-flag__img {
  105. padding-right: $inuit-global-spacing-unit-large;
  106. }
  107. &.o-flag--reverse {
  108. > .o-flag__img {
  109. padding-right: 0;
  110. padding-left: $inuit-global-spacing-unit-large;
  111. }
  112. }
  113. }
  114. .o-flag--huge {
  115. > .o-flag__img {
  116. padding-right: $inuit-global-spacing-unit-huge;
  117. }
  118. &.o-flag--reverse {
  119. > .o-flag__img {
  120. padding-right: 0;
  121. padding-left: $inuit-global-spacing-unit-huge;
  122. }
  123. }
  124. }
  125. /* Reversed flag
  126. ========================================================================== */
  127. /**
  128. * 1. Swap the rendered direction of the object…
  129. * 2. …and reset it.
  130. * 3. Reassign margins to the correct sides.
  131. */
  132. .o-flag--reverse {
  133. direction: rtl; /* [1] */
  134. > .o-flag__img,
  135. > .o-flag__body {
  136. direction: ltr; /* [2] */
  137. }
  138. > .o-flag__img {
  139. padding-right: 0; /* [3] */
  140. padding-left: $inuit-global-spacing-unit; /* [3] */
  141. }
  142. }
  143. /* Alignment variants
  144. ========================================================================== */
  145. /**
  146. * Vertically align the image- and body-content differently. Defaults to middle.
  147. */
  148. .o-flag--top {
  149. > .o-flag__img,
  150. > .o-flag__body {
  151. vertical-align: top;
  152. }
  153. }
  154. .o-flag--bottom {
  155. > .o-flag__img,
  156. > .o-flag__body {
  157. vertical-align: bottom;
  158. }
  159. }