6. 实例

下面是含有上述约定的示例代码:

  1. /* ==========================================================================
  2. Grid layout
  3. ========================================================================== */
  4. /**
  5. * Column layout with horizontal scroll.
  6. *
  7. * This creates a single row of full-height, non-wrapping columns that can
  8. * be browsed horizontally within their parent.
  9. *
  10. * Example HTML:
  11. *
  12. * <div class="grid">
  13. * <div class="cell cell-3"></div>
  14. * <div class="cell cell-3"></div>
  15. * <div class="cell cell-3"></div>
  16. * </div>
  17. */
  18. /**
  19. * Grid container
  20. *
  21. * Must only contain `.cell` children.
  22. *
  23. * 1. Remove inter-cell whitespace
  24. * 2. Prevent inline-block cells wrapping
  25. */
  26. .grid {
  27. height: 100%;
  28. font-size: 0; /* 1 */
  29. white-space: nowrap; /* 2 */
  30. }
  31. /**
  32. * Grid cells
  33. *
  34. * No explicit width by default. Extend with `.cell-n` classes.
  35. *
  36. * 1. Set the inter-cell spacing
  37. * 2. Reset white-space inherited from `.grid`
  38. * 3. Reset font-size inherited from `.grid`
  39. */
  40. .cell {
  41. position: relative;
  42. display: inline-block;
  43. overflow: hidden;
  44. box-sizing: border-box;
  45. height: 100%;
  46. padding: 0 10px; /* 1 */
  47. border: 2px solid # 333;
  48. vertical-align: top;
  49. white-space: normal; /* 2 */
  50. font-size: 16px; /* 3 */
  51. }
  52. /* Cell states */
  53. .cell.is-animating {
  54. background-color: # fffdec;
  55. }
  56. /* Cell dimensions
  57. ========================================================================== */
  58. .cell-1 { width: 10%; }
  59. .cell-2 { width: 20%; }
  60. .cell-3 { width: 30%; }
  61. .cell-4 { width: 40%; }
  62. .cell-5 { width: 50%; }
  63. /* Cell modifiers
  64. ========================================================================== */
  65. .cell--detail,
  66. .cell--important {
  67. border-width: 4px;
  68. }