CSS

cheatsheet
  1. CSS Boiler plate
  2. *{
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }
            html , body{
                height: 100%;
                width: 100%;
            }
  3. CSS selector (class)
  4. .container {
                    width: 100%;
                }
  5. CSS selector (id)
  6. #header {
                    background-color: gray;
                }
  7. CSS selector (multiple elements)
  8. h1, h2, h3 {
                    font-family: Arial, sans-serif;
                }
  9. CSS selector (descendant)
  10. .container p {
                    font-size: 16px;
                }
  11. CSS selector (child)
  12. .container > ul {
                    list-style-type: none;
                }
  13. CSS selector (adjacent sibling)
  14. h2 + p {
                    margin-top: 10px;
                }
  15. CSS selector (attribute)
  16. input[type="text"] {
                    border: 1px solid #ccc;
                }
  17. CSS selector (pseudo-class)
  18. a:hover {
                    color: red;
                }
  19. CSS selector (pseudo-element)
  20. p::first-line {
                    font-weight: bold;
                }
  21. CSS property (color)
  22. p {
                    color: green;
                }
  23. CSS property (background-color)
  24. body {
                    background-color: #f0f0f0;
                }
  25. CSS property (font-family)
  26. p {
                    font-family: Arial, sans-serif;
                }
  27. CSS property (font-size)
  28. p {
                    font-size: 16px;
                }
  29. CSS property (font-weight)
  30. p {
                    font-weight: bold;
                }
  31. CSS property (text-align)
  32. p {
                    text-align: center;
                }
  33. CSS property (padding)
  34. .container {
                    padding: 10px;
                }
  35. CSS property (margin)
  36. p {
                    margin: 0;
                }
  37. CSS property (border)
  38. div {
                    border: 1px solid #000;
                }
  39. CSS property (width)
  40. .container {
                    width: 100%;
                }
  41. CSS property (height)
  42. .container {
                    height: 200px;
                }
  43. CSS property (display)
  44. span {
                    display: inline-block;
                }
  45. CSS property (position)
  46. .element {
                    position: relative;
                    top: 10px;
                    left: 20px;
                }
  47. CSS property (float)
  48. img {
                    float: right;
                }
  49. CSS property (clear)
  50. .clearfix::after {
                    content: "";
                    display: table;
                    clear: both;
                }
  51. CSS property (background-image)
  52. div {
                    background-image: url("background.jpg");
                }
  53. CSS property (background-size)
  54. div {
                    background-size: cover;
                }
  55. CSS property (opacity)
  56. div {
                    opacity: 0.5;
                }
  57. CSS property (box-shadow)
  58. div {
                    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
                }
  59. CSS property (text-decoration)
  60. a {
                    text-decoration: none;
                }
  61. CSS property (transition)
  62. button {
                    transition: background-color 0.3s ease;
                }
  63. CSS property (border-radius)
  64. .rounded {
        border-radius: 5px;
    }
  65. CSS property (box-sizing)
  66. * {
        box-sizing: border-box;
    }
  67. CSS property (text-transform)
  68. .uppercase {
        text-transform: uppercase;
    }
  69. CSS property (overflow)
  70. div {
        overflow: hidden;
    }
  71. CSS property (z-index)
  72. .overlay {
        position: absolute;
        z-index: 999;
    }
  73. CSS property (cursor)
  74. button {
        cursor: pointer;
    }
  75. CSS property (pointer-events)
  76. a.disabled {
        pointer-events: none;
    }
  77. CSS property (outline)
  78. a:focus {
        outline: 2px solid blue;
    }
  79. CSS property (word-wrap)
  80. p {
        word-wrap: break-word;
    }
  81. CSS property (text-overflow)
  82. div {
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
  83. CSS property (white-space)
  84. pre {
        white-space: pre-wrap;
    }
  85. CSS property (positioning: absolute)
  86. .popup {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
  87. CSS property (positioning: fixed)
  88. .sidebar {
        position: fixed;
        top: 0;
        left: 0;
    }
  89. CSS property (positioning: relative)
  90. .container {
        position: relative;
    }
  91. CSS property (positioning: sticky)
  92. .sticky {
        position: sticky;
        top: 0;
    }
  93. CSS property (flexbox: container)
  94. .flex-container {
        display: flex;
    }
  95. CSS property (flexbox: direction)
  96. .flex-container {
        flex-direction: row;
    }
  97. CSS property (flexbox: justify-content)
  98. .flex-container {
        justify-content: center;
    }
  99. CSS property (flexbox: align-items)
  100. .flex-container {
        align-items: center;
    }
  101. CSS property (flexbox: flex)
  102. .flex-item {
        flex: 1;
    }
  103. CSS property (grid: container)
  104. .grid-container {
        display: grid;
        grid-template-columns: auto auto auto;
    }
  105. CSS property (grid: column gap)
  106. .grid-container {
        grid-column-gap: 10px;
    }
  107. CSS property (grid: row gap)
  108. .grid-container {
        grid-row-gap: 10px;
    }
  109. CSS property (grid: column span)
  110. .grid-item {
        grid-column: span 2;
    }
  111. CSS property (grid: row span)
  112. .grid-item {
        grid-row: span 2;
    }
  113. CSS property (grid: column start)
  114. .grid-item {
        grid-column-start: 2;
    }
  115. CSS property (grid: column end)
  116. .grid-item {
        grid-column-end: 4;
    }
  117. CSS property (grid: row start)
  118. .grid-item {
        grid-row-start: 2;
    }
  119. CSS property (grid: row end)
  120. .grid-item {
        grid-row-end: 4;
    }
  121. CSS property (grid: area)
  122. .grid-item {
        grid-area: 1 / 1 / 2 / 3;
    }
  123. CSS property (transform: translate)
  124. .translate {
        transform: translate(50px, 100px);
    }
  125. CSS property (transform: rotate)
  126. .rotate {
        transform: rotate(45deg);
    }
  127. CSS property (transform: scale)
  128. .scale {
        transform: scale(1.5);
    }
  129. CSS property (transform: skew)
  130. .skew {
        transform: skew(20deg, 10deg);
    }
  131. CSS property (transition: property)
  132. button {
        transition: background-color 0.3s ease;
    }
  133. CSS property (transition: duration)
  134. button {
        transition: background-color 1s;
    }
  135. CSS property (transition: timing function)
  136. button {
        transition: background-color 0.3s ease-in-out;
    }
  137. CSS property (transition: delay)
  138. button {
        transition: background-color 0.3s ease 1s;
    }
  139. CSS property (animation: name)
  140. @keyframes example {
        from {background-color: red;}
        to {background-color: yellow;}
    }
    
    div {
        animation-name: example;
    }
  141. CSS property (animation: duration)
  142. @keyframes example {
        from {background-color: red;}
        to {background-color: yellow;}
    }
    
    div {
        animation-name: example;
        animation-duration: 4s;
    }
  143. CSS property (animation: timing function)
  144. @keyframes example {
        from {background-color: red;}
        to {background-color: yellow;}
    }
    
    div {
        animation-name: example;
        animation-timing-function: ease-in-out;
    }
  145. CSS property (animation: delay)
  146. @keyframes example {
        from {background-color: red;}
        to {background-color: yellow;}
    }
    
    div {
        animation-name: example;
        animation-delay: 2s;
    }
  147. CSS property (animation: iteration count)
  148. @keyframes example {
        from {background-color: red;}
        to {background-color: yellow;}
    }
    div {
        animation-name: example;
        animation-iteration-count: 3;
    }
  149. CSS selector (element)
  150. p {
        color: blue;
    }
  151. CSS comment
  152. /* This is a CSS comment */