Advertisement
decembre

CSS - FLEXBOX v.1

May 8th, 2016
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. ============================
  2. ======== CSS - FLEXBOX v.1 - POSTé
  3. ============================
  4.  
  5. ============================
  6. ======== Using CSS flexible boxes : FLEXBOX CONTEXT Browser compatibility
  7. == https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes?redirectlocale=en-US&redirectslug=CSS%2FTutorials%2FUsing_CSS_flexible_boxes
  8.  
  9. for FIREFOX 21:
  10. about:config preference:
  11. "layout.css.flexbox.enabled" to true.
  12.  
  13. ============================
  14. ======== FLEXBOX CONTEXT
  15. == http://css-tricks.com/using-flexbox/
  16. == https://developer.mozilla.org/en-US/docs/Web/CSS/align-items
  17. We need to make the container for our columns a flexbox display context.
  18. Just by doing this, all direct children of this element become flex items.
  19. Doesn't matter what they were before, they are flex items now.
  20.  
  21. Right away we need to weave the old, new, and tweener syntaxes together.
  22. ORDER IS IMPORTANT HERE.
  23. Since the display property itself isn't prefixed,
  24. we need to make sure we don't override newer syntaxes with older syntaxes
  25. for browsers that still (and probably always will) support both.
  26.  
  27. .page-wrap {
  28. display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
  29. display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
  30. display: -ms-flexbox; /* TWEENER - IE 10 */
  31. display: -webkit-flex; /* NEW - Chrome */
  32. display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
  33. }
  34.  
  35.  
  36. ============================
  37. ======== FLEXBOX CSS ALIGN-ITEMS
  38. == http://www.w3schools.com/cssref/css3_pr_align-items.asp
  39. == DEMO INTERACTIVE : http://www.w3schools.com/cssref/playit.asp?filename=playcss_align-items&preval=center
  40.  
  41. VALUES:
  42. stretch Default. Items are stretched to fit the container
  43. center Items are positioned at the center of the container
  44. flex-start Items are positioned at the beginning of the container
  45. flex-end Items are positioned at the end of the container
  46. baseline Items are positioned at the baseline of the container
  47. initial Sets this property to its default value. Read about initial
  48. inherit Inherits this property from its parent element. Read about inherit
  49.  
  50.  
  51. EAMPLE :
  52. div {
  53. display: -webkit-flex; /* Safari */
  54. -webkit-align-items: center; /* Safari 7.0+ */
  55. display: flex;
  56. align-items: center;
  57. }
  58.  
  59. ============================
  60. ======== CONTROLLING COLUMN WIDTHS
  61. == http://css-tricks.com/using-flexbox/
  62. Our goal here is a 20% / 60% / 20% grid.
  63.  
  64. Step 1 is to set our main content to the 60%.
  65. Step 2 is to set the outside sidebars to fill the remaining space equally.
  66.  
  67. Again we need to weave together old, new, and tweener syntaxes.
  68.  
  69. .main-content {
  70. width: 60%;
  71. }
  72. .main-nav,
  73. .main-sidebar {
  74. -webkit-box-flex: 1; /* OLD - iOS 6-, Safari 3.1-6 */
  75. -moz-box-flex: 1; /* OLD - Firefox 19- */
  76. width: 20%; /* For old syntax, otherwise collapses. */
  77. -webkit-flex: 1; /* Chrome */
  78. -ms-flex: 1; /* IE 10 */
  79. flex: 1; /* NEW, Spec - Opera 12.1, Firefox 20+ */
  80. }
  81. == COLUMN RE-ORDERING
  82.  
  83. We want the main content to visually appear in the middle, but be first in the source order.
  84. Easy cheesy in flexbox, but of course we need to weave together the new, old, and tweener syntaxes.
  85.  
  86. .main-content {
  87. -webkit-box-ordinal-group: 2; /* OLD - iOS 6-, Safari 3.1-6 */
  88. -moz-box-ordinal-group: 2; /* OLD - Firefox 19- */
  89. -ms-flex-order: 2; /* TWEENER - IE 10 */
  90. -webkit-order: 2; /* NEW - Chrome */
  91. order: 2; /* NEW, Spec - Opera 12.1, Firefox 20+ */
  92. }
  93. .main-nav {
  94. -webkit-box-ordinal-group: 1;
  95. -moz-box-ordinal-group: 1;
  96. -ms-flex-order: 1;
  97. -webkit-order: 1;
  98. order: 1;
  99. }
  100. .main-sidebar {
  101. -webkit-box-ordinal-group: 3;
  102. -moz-box-ordinal-group: 3;
  103. -ms-flex-order: 3;
  104. -webkit-order: 3;
  105. order: 3;
  106. }
  107.  
  108.  
  109.  
  110. ============================
  111. ======== FLEX-FLOW : flex-flow
  112. == http://www.w3.org/TR/css3-flexbox/
  113. == <a href="http://stackoverflow.com/questions/7813783/firefox-and-flexbox-when-using-white-space-nowrap-on-child-element-the-flexib?rq=1">Firefox and flexbox</a>
  114.  
  115. @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,600,700);
  116. * {
  117. margin: 0;
  118. padding: 0;
  119. @include box-sizing(border-box);
  120. }
  121.  
  122. body {
  123. padding: 5%;
  124. font-family: 'Open Sans';
  125. font-size: 1em;
  126. }
  127.  
  128. .container {
  129. display: -webkit-box;
  130. display: -moz-box;
  131. display: -ms-flexbox;
  132. display: -webkit-flex;
  133. display: flex;
  134.  
  135. -webkit-flex-flow: row wrap;
  136. -moz-flex-flow: row wrap;
  137. -ms-flex-flow: row wrap;
  138. -ms-flex-direction: row;
  139. -ms-flex-wrap: wrap;
  140. flex-flow: row wrap;
  141.  
  142. margin: 0 auto;
  143. max-width: 1500px;
  144.  
  145. @media (max-width: 700px) {
  146. -webkit-flex-flow: column wrap;
  147. -moz-flex-flow: column wrap;
  148. -ms-flex-flow: column wrap;
  149. -ms-flex-direction: column;
  150. -ms-flex-wrap: wrap;
  151. flex-flow: column wrap;
  152. }
  153. }
  154. .header {
  155. padding: 1em 0.5em;
  156. width: 100%;
  157. height: 100px;
  158. background: #cdc9bb;
  159.  
  160. @media (max-width: 700px) {
  161. -webkit-box-ordinal-group: 2;
  162. -moz-box-ordinal-group: 2;
  163. -ms-flex-order: 2;
  164. -webkit-order: 2;
  165. order: 2;
  166. }
  167. }
  168. .content {
  169. -webkit-box-flex: 1;
  170. -webkit-flex: 1;
  171. -moz-box-flex: 1;
  172. -ms-flex: 1;
  173. flex: 1;
  174.  
  175. padding: 1em;
  176. background: #e7e3d4;
  177.  
  178. @media (max-width: 700px) {
  179. -webkit-box-ordinal-group: 3;
  180. -moz-box-ordinal-group: 3;
  181. -ms-flex-order: 3;
  182. -webkit-order: 3;
  183. order: 3;
  184. }
  185. }
  186. .nav {
  187. width: 200px;
  188. padding: 1em 0.5em;
  189. background: #eceae4;
  190.  
  191. @media (max-width: 700px) {
  192. -webkit-box-ordinal-group: 1;
  193. -moz-box-ordinal-group: 1;
  194. -ms-flex-order: 1;
  195. -webkit-order: 1;
  196. order: 1;
  197. width: 100%;
  198. }
  199. }
  200. .aside {
  201. width: 140px;
  202. padding: 1em 0.5em;
  203. background: #f8f8f6;
  204.  
  205. @media (max-width: 700px) {
  206. -webkit-box-ordinal-group: 4;
  207. -moz-box-ordinal-group: 4;
  208. -ms-flex-order: 4;
  209. -webkit-order: 4;
  210. order: 4;
  211.  
  212. width: 100%;
  213. }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement