From d08889ae62d368ee8e7894544827b6de80e06651 Mon Sep 17 00:00:00 2001 From: Sumangal44 <123644743+Sumangal44@users.noreply.github.com> Date: Mon, 27 May 2024 23:14:38 +0530 Subject: [PATCH] new css cheetsheet update --- source/_posts/css3.md | 821 +++++++++++++++++++++++++++--------------- 1 file changed, 540 insertions(+), 281 deletions(-) diff --git a/source/_posts/css3.md b/source/_posts/css3.md index 1cfc197..259b5c1 100644 --- a/source/_posts/css3.md +++ b/source/_posts/css3.md @@ -3,81 +3,81 @@ title: CSS 3 date: 2020-12-25 20:22:47 background: bg-[#3473b5] tags: - - web - - css - - style + - web + - css + - style categories: - - Programming + - Programming intro: | - This is a quick reference cheat sheet for CSS goodness, listing selector syntax, properties, units and other useful bits of information. + This is a quick reference cheat sheet for CSS goodness, listing selector syntax, properties, units and other useful bits of information. plugins: - - copyCode + - copyCode --- - - -Getting Started ------------- +## Getting Started ### Introduction {.row-span-3} + CSS is rich in capabilities and is more than simply laying out pages. #### External stylesheet + ```html {.wrap} - + ``` #### Internal stylesheet + ```html ``` -#### Inline styles +#### Inline styles + ```html {.wrap}

Centered text

Blue, 18-point text

``` - ### Add class ```html
``` + Support multiple classes on one element. - - ### !important ```css .post-title { - color: blue !important; + color: blue !important; } ``` Overrides all previous styling rules. - ### Selector ```css -h1 { } -#job-title { } -div.hero { } -div > p { } +h1 { +} +#job-title { +} +div.hero { +} +div > p { +} ``` See: [Selectors](#css-selectors) - - ### Text color ```css @@ -89,9 +89,6 @@ color: hsla(30 100% 50% / 0.6); See: [Colors](#css-colors) - - - ### Background ```css @@ -102,75 +99,64 @@ background-image: url("../image.png"); See: [Backgrounds](#css-backgrounds) - - ### Font ```css .page-title { - font-weight: bold; - font-size: 30px; - font-family: "Courier New"; + font-weight: bold; + font-size: 30px; + font-family: "Courier New"; } ``` + See: [Fonts](#css-fonts) - - - ### Position ```css .box { - position: relative; - top: 20px; - left: 20px; + position: relative; + top: 20px; + left: 20px; } ``` See also: [Position](https://learn-the-web.algonquindesign.ca/topics/css-layout-cheat-sheet/) - - ### Animation -```css +```css animation: 300ms linear 0s infinite; animation: bounce 300ms linear infinite; - ``` + See: [Animation](#css-animation) - ### Comment -```css +```css /* This is a single line comment */ /* This is a multi-line comment */ ``` - ### Flex layout ```css div { - display: flex; - justify-content: center; + display: flex; + justify-content: center; } div { - display: flex; - justify-content: flex-start; + display: flex; + justify-content: flex-start; } ``` See: [Flexbox](#css-flexbox) | [Flex Tricks](#css-flexbox-tricks) - - - ### Grid layout ```css @@ -188,9 +174,8 @@ See: [Flexbox](#css-flexbox) | [Flex Tricks](#css-flexbox-tricks) See: [Grid Layout](#css-grid-layout) - - ### Variable & Counter + ```css counter-set: subsection; counter-increment: subsection; @@ -206,38 +191,45 @@ element { See: [Dynamic content](#css-dynamic-content) +## CSS Selectors -CSS Selectors ------------ - - -### Examples {.row-span-2} +### Examples {.row-span-2} #### Groups Selector + ```css -h1, h2 { - color: red; +h1, +h2 { + color: red; } ``` -#### Chaining Selector + +#### Chaining Selector + ```css h3.section-heading { - color: blue; + color: blue; } ``` + #### Attribute Selector + ```css div[attribute="SomeValue"] { - background-color: red; + background-color: red; } ``` + #### First Child Selector + ```css p:first-child { - font-weight: bold; + font-weight: bold; } ``` + #### No Children Selector + ```css .box:empty { background: lime; @@ -246,42 +238,40 @@ p:first-child { } ``` - ### Basic | | | -|--------------|-----------------------------| +| ------------ | --------------------------- | | `*` | All elements | | `div` | All div tags | | `.classname` | All elements with class | | `#idname` | Element with ID | | `div,p` | All divs and paragraphs | | `#idname *` | All elements inside #idname | -See also: [Type](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors) / [Class](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) / [ID](https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors) / [Universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors) selectors +See also: [Type](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors) / [Class](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) / [ID](https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors) / [Universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors) selectors ### Combinators | Selector | Description | -|-----------------|---------------------------------------| +| --------------- | ------------------------------------- | | `div.classname` | Div with certain classname | | `div#idname` | Div with certain ID | | `div p` | Paragraphs inside divs | | `div > p` | All p tags
_one level deep in div_ | | `div + p` | P tags immediately after div | | `div ~ p` | P tags preceded by div | + See also: [Adjacent](https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator) / [Sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator) / [Child](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator) selectors - - ### Attribute selectors | | | -|----------------------|------------------------------------| +| -------------------- | ---------------------------------- | ---------------------------- | | `a[target]` | With a target attribute | | `a[target="_blank"]` | Open in new tab | | `a[href^="/index"]` | Starts with /index | -| `[class|="chair"]` | Starts with chair | +| `[class | ="chair"]` | Starts with chair | | `[class*="chair"]` | containing chair | | `[title~="chair"]` | Contains the word chair | | `a[href$=".doc"]` | Ends with .doc | @@ -289,22 +279,19 @@ See also: [Adjacent](https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_s See also: [Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) - - - ### User action pseudo classes + | | | -|--------------|-------------------------| +| ------------ | ----------------------- | | `a:link ` | Link in normal state | | `a:active ` | Link in clicked state | | `a:hover ` | Link with mouse over it | | `a:visited ` | Visited link | - - ### Pseudo classes + | | | -|-------------------|-----------------------------------------------------------------------------------------| +| ----------------- | --------------------------------------------------------------------------------------- | | `p::after` | Add content after p | | `p::before` | Add content before p | | `p::first-letter` | First letter in p | @@ -317,11 +304,10 @@ See also: [Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS | `p:lang(en)` | P with en language attribute | | `:not(span)` | Element that's not a span | - - ### Input pseudo classes + | | | -|-----------------------|---------------------------------------------------------------------------------------------| +| --------------------- | ------------------------------------------------------------------------------------------- | | `input:checked` | Checked inputs | | `input:disabled` | Disabled inputs | | `input:enabled` | Enabled inputs | @@ -336,11 +322,10 @@ See also: [Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS | `input:read-write` | No readonly attribute | | `input:indeterminate` | With [indeterminate](https://developer.mozilla.org/en-US/docs/Web/CSS/:indeterminate) state | - - ### Structural pseudo classes + | | | -|-------------------------|----------------------------| +| ----------------------- | -------------------------- | | `p:first-child` | First child | | `p:last-child` | Last child | | `p:first-of-type` | First of some type | @@ -353,27 +338,23 @@ See also: [Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS | `p:only-of-type` | Unique of its parent | | `p:only-child` | Only child of its parent | - - -CSS Fonts ------- - +## CSS Fonts ### Properties {.row-span-3} | Property | Description | -|-------------------|-----------------| +| ----------------- | --------------- | | `font-family:` | \ | | `font-size:` | \ | | `letter-spacing:` | \ | | `line-height:` | \ | -| `font-weight:` | \ / bold / normal | -| `font-style:` | italic / normal | -| `text-decoration:` | underline / none | +| `font-weight:` | \ / bold / normal | +| `font-style:` | italic / normal | +| `text-decoration:` | underline / none | -| `text-align:` | left / right
center / justify | -| `text-transform:` | capitalize / uppercase / lowercase | +| `text-align:` | left / right
center / justify | +| `text-transform:` | capitalize / uppercase / lowercase | {.left-text} See also: [Font](https://developer.mozilla.org/en-US/docs/Web/CSS/font) @@ -381,7 +362,7 @@ See also: [Font](https://developer.mozilla.org/en-US/docs/Web/CSS/font) ### Shorthand {.secondary .col-span-2} | | style | weight | size (required) | | line-height | family | -|---------|----------|--------|-----------------|-----|-------------|-------------------| +| ------- | -------- | ------ | --------------- | --- | ----------- | ----------------- | | `font:` | `italic` | `400` | `14px` | `/` | `1.5` | `sans-serif` | | | style | weight | size (required) | | line-height | family (required) | @@ -393,11 +374,9 @@ font-size: 12pt; letter-spacing: 0.02em; ``` - ### Case {.row-span-2} ```css - /* Hello */ text-transform: capitalize; @@ -408,22 +387,16 @@ text-transform: uppercase; text-transform: lowercase; ``` - ### @font-face ```css @font-face { - font-family: 'Glegoo'; - src: url('../Glegoo.woff'); + font-family: "Glegoo"; + src: url("../Glegoo.woff"); } ``` - - - -CSS Colors ------------- - +## CSS Colors ### Named color @@ -434,7 +407,6 @@ color: tan; color: rebeccapurple; ``` - ### Hexadecimal color ```css @@ -444,8 +416,6 @@ color: #090a; color: #009900aa; ``` - - ### rgb() Colors ```css @@ -453,11 +423,10 @@ color: rgb(34, 12, 64, 0.6); color: rgba(34, 12, 64, 0.6); color: rgb(34 12 64 / 0.6); color: rgba(34 12 64 / 0.3); -color: rgb(34.0 12 64 / 60%); +color: rgb(34 12 64 / 60%); color: rgba(34.6 12 64 / 30%); ``` - ### HSL Colors ```css @@ -465,11 +434,12 @@ color: hsl(30, 100%, 50%, 0.6); color: hsla(30, 100%, 50%, 0.6); color: hsl(30 100% 50% / 0.6); color: hsla(30 100% 50% / 0.6); -color: hsl(30.0 100% 50% / 60%); +color: hsl(30 100% 50% / 60%); color: hsla(30.2 100% 50% / 60%); ``` ### Other + ```css color: inherit; color: initial; @@ -479,34 +449,27 @@ color: transparent; color: currentcolor; /* keyword */ ``` - - - - - - -CSS Backgrounds ----------- +## CSS Backgrounds ### Properties {.row-span-2} | Property | Description | -|---------------|---------------| +| ------------- | ------------- | | `background:` | _(Shorthand)_ | -| `background-color:` | See: [Colors](#css-colors) | -| `background-image:` | url(...) | -| `background-position:` | left/center/right
top/center/bottom | -| `background-size:` | cover X Y | -| `background-clip:` | border-box
padding-box
content-box | -| `background-repeat:` | no-repeat
repeat-x
repeat-y | -| `background-attachment:` | scroll/fixed/local | +| `background-color:` | See: [Colors](#css-colors) | +| `background-image:` | url(...) | +| `background-position:` | left/center/right
top/center/bottom | +| `background-size:` | cover X Y | +| `background-clip:` | border-box
padding-box
content-box | +| `background-repeat:` | no-repeat
repeat-x
repeat-y | +| `background-attachment:` | scroll/fixed/local | {.left-text} ### Shorthand {.secondary .col-span-2} | | color | image | positionX | positionY | | size | repeat | attachment | -|---------------|--------|--------------|-----------|-----------|-----|----------------|-------------|------------| +| ------------- | ------ | ------------ | --------- | --------- | --- | -------------- | ----------- | ---------- | | `background:` | `#ff0` | `url(a.jpg)` | `left` | `top` | `/` | `100px` `auto` | `no-repeat` | `fixed;` | | `background:` | `#abc` | `url(b.png)` | `center` | `center` | `/` | `cover` | `repeat-x` | `local;` | | | color | image | posX | posY | | size | repeat | attach.. | @@ -516,100 +479,95 @@ CSS Backgrounds ```css {.wrap} background: url(img_man.jpg) no-repeat center; -background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top repeat; +background: url(img_flwr.gif) right bottom no-repeat, url(paper.gif) left top + repeat; -background: rgb(2,0,36); -background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(13,232,230,1) 35%, rgba(0,212,255,1) 100%); +background: rgb(2, 0, 36); +background: linear-gradient( + 90deg, + rgba(2, 0, 36, 1) 0%, + rgba(13, 232, 230, 1) 35%, + rgba(0, 212, 255, 1) 100% +); ``` - - - -CSS The Box Model ------------- - +## CSS The Box Model ### Maximums/Minimums ```css .column { - max-width: 200px; - width: 500px; + max-width: 200px; + width: 500px; } ``` -See also: [max-width](https://developer.mozilla.org/en-US/docs/Web/CSS/max-width) / [min-width](https://developer.mozilla.org/en-US/docs/Web/CSS/min-width) / [max-height](https://developer.mozilla.org/en-US/docs/Web/CSS/max-height) / [min-height](https://developer.mozilla.org/en-US/docs/Web/CSS/min-height) - +See also: [max-width](https://developer.mozilla.org/en-US/docs/Web/CSS/max-width) / [min-width](https://developer.mozilla.org/en-US/docs/Web/CSS/min-width) / [max-height](https://developer.mozilla.org/en-US/docs/Web/CSS/max-height) / [min-height](https://developer.mozilla.org/en-US/docs/Web/CSS/min-height) ### Margin / Padding ```css .block-one { - margin: 20px; - padding: 10px; + margin: 20px; + padding: 10px; } ``` -See also: [Margin](https://developer.mozilla.org/en-US/docs/Web/CSS/margin) / [Padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding) +See also: [Margin](https://developer.mozilla.org/en-US/docs/Web/CSS/margin) / [Padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding) ### Box-sizing ```css .container { - box-sizing: border-box; + box-sizing: border-box; } ``` + See also: [Box-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/Box-sizing) - - -### Visibility +### Visibility ```css .invisible-elements { - visibility: hidden; + visibility: hidden; } ``` -See also: [Visibility](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) +See also: [Visibility](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) ### Auto keyword ```css div { - margin: auto; + margin: auto; } ``` -See also: [Margin](https://developer.mozilla.org/en-US/docs/Web/CSS/margin) +See also: [Margin](https://developer.mozilla.org/en-US/docs/Web/CSS/margin) ### Overflow ```css .small-block { - overflow: scroll; + overflow: scroll; } ``` + See also: [Overflow](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow) - - - -CSS Animation {.cols-5} ---------- - +## CSS Animation {.cols-5} ### Shorthand {.col-span-5 .secondary} | | name | duration | timing-function | delay | count | direction | fill-mode | play-state | -|--------------|----------|----------|-----------------|---------|------------|---------------------|-----------|------------| +| ------------ | -------- | -------- | --------------- | ------- | ---------- | ------------------- | --------- | ---------- | | `animation:` | `bounce` | `300ms` | `linear` | `100ms` | `infinite` | `alternate-reverse` | `both` | `reverse` | | | name | duration | timing-function | delay | count | direction | fill-mode | play-state | ### Properties {.row-span-2 .col-span-2} | Property | Value | -|------------------------------|--------------------------------------------------------| +| ---------------------------- | ------------------------------------------------------ | | `animation:` | _(shorthand)_ | | `animation-name:` | \ | | `animation-duration:` | \