[!DOCTYPE html] [html] [head] [!--add title here like this: --] [title] Banana Cheatsheet [/title] [!--link to css stylesheet like this: --] [link href="styles.css" rel="stylesheet"] [!--embed google font here, like this: --] [link rel="preconnect" href="https://fonts.googleapis.com"] [!--learn more at Font --] [/head] [body] where header, body, footer and various attributes goes here more about this at HTML [/body] [/html] *replace [ and ] with < and >
element | explanation |
---|---|
$ ls | (LS) the terminal would display our current directory’s files and directories |
$ pwd | Print working directory - show where you are in the file system |
$ cd | Change directory |
$ cd .. | the argument . . stands for the directory above the current working directory. |
$ cd ../.. | move the directory 2 path above |
$ cd ../2014 | move to above, then to folder 2014 |
$ mkdir media | make directory / create new directory named media inside working directory |
$ touch keyboard.txt | creates new file (in this case keyboard.txt) inside working directory |
element | explanation | variations |
---|---|---|
Ordered list | list appeared with 123 | [ol][li]content1[/li][li]content2[/li][/ol] |
Unordered list | list appeared with a dot | [ul][li]content1[/li][li]content2[/li][/ul] |
Image | attach image. It has no close tag | [img src="link] |
Video | attach image. It has a close tag, in which have to add description in case video doesn't load | [video src="link"] add description [/video] |
Include control for video | [video src="link" controls] add description [/video] | |
Audio | Insert audio on website | [audio control] [source src="link to audio.mp3" type="audio/mp3"] [/audio] |
Figure Caption | Insert figure caption | [figure] [img src="link.jpg"] [figcaption] Insert Caption [/figcaption] [/figure] |
Embed | Embed gif into paragraph or any element | [embed src="down.oad.gif"/] |
Link | to link to new page, add the target | [a href="link" target"_blank"] words that will be transformed into link[/a] |
to link to same page | [a href="link"] words that will be transformed into link[/a] | |
to add an anchor to same page: use id selector | [p id="top"]This is the top[/p] [a href="#top"] This link will bring you to the top[/a] | |
Comment | item in comment will not be displayed on the website | [!--insert your comment here--] |
Other elements | can be written as:HTML styleor | [header] [nav] [body] [footer] [section] [article] [aside] [h1] all the way to [h6] [p] all of which need closing tag |
DIV style | [div class="header"] [div class="nav"] [div class="body"] [div class="footer"] [div class="section"] [div class="article"] [div class="aside"] [div class="h1"] all the way to [div class="h6"] [div class="p"] all of which need closing tag of [/div] |
*replace [ and ] with < and > when applicable
element | explanation | variations |
---|---|---|
Class | can have multiple ID - can only be used once | HTML [h1 class="title"] THIS IS THE TITLE [/h1] CSS .title { color: teal; } |
ID | can only be used once, most prominent selector | HTML [h1 id="article-title"] THIS IS THE TITLE [/h1] CSS #article-title { color: yellow; } |
Multiple Selector | Instead of writing same instructions multiple times, can be shortened. | h2,.menu { font-family: Tahoma; } example above will select h2 element and menu class to have the same font |
Chaining | CSS style will be for elements within class specifications | h2.destination { font-family: Tahoma; } example above will select h2 element within the class of destination to have font of Tahoma |
Descendant combinator | almost similar to chaining. Chaining is more specific while Descendant combinator combines two selectors to select elements that have ancestor element that matches the first selector | HTML [div class="destination"] [h1]THIS IS THE TITLE [/h1] [p]This is paragraph[/p] [/div] CSS .destination h1 { color: yellow; } this will select h1 element under class destination |
Pseudo Class | A pseudo-class can be attached to any selector. It is always written as a colon : followed by a name. For example p:hover.
Value:
|
p:hover { background-color: lime; } |
*replace [ and ] with < and > when applicable
element | explanation | variations |
---|---|---|
Width and Height | width and height of the content | width: 100%;height: 10px; |
Margin | gaps between border and other elements. Shortcut:
|
margin-top/margin-right/margin-bottom/margin-leftmargin: 6px, 7px, 8px, 9px;margin: 7px, 8px, 9px;margin: 8px, 9px;margin: 9px; |
Border | between margin and padding | border: 3px solid red;border-radius: 5px; |
Padding | between content and border. Shortcut:
|
padding-top/padding-right/padding-bottom/padding-leftpadding: 6px, 7px, 8px, 9px;padding: 7px, 8px, 9px;padding: 8px, 9px;padding: 9px; |
Min and Max | min and max width / height of a content. | min-width / min-height / max-width / max-height |
Overflow | what will happen if the content spills / overflow. Values: hidden - when set to this value, any content that overflows will be hidden from view. scroll - when set to this value, a scrollbar will be added to the element box. visible - when set to this value, the overflow content will be displayed outside of the containing element. This is the default. | overflow: scroll; |
Visibility | Elements can be hidden from view with the visibility property. Values: hidden - hides an element visible - displays an element collapse - collapse an element | visibility: hidden; |
Position | static: the default position. It doesn't need to be specified. | position: static; |
relative: in relative to static position of the web page. Can move top bottom left right | .question { position: relative; top: 40px; } | |
absolute: all the other element will ignore the element and act like its not present on the page. | .question { position: absolute; } | |
fixed: fix the element to a specific position on the page regardless of user scrolling/ | .question { position: fixed; top: 0px; left: 0px; } | |
sticky: keeps an element in the document flow as the user scrolls, but sticks to a specific position as the page is scrolled further | .question { position: sticky; top: 240px; } | |
Z-index | controls how far back or forward an element should appear on the web page when elements overlap. | .question { position: relative; z-index: 1; } |
Display | Inline - styled inside HTML beside the line where they want to style. Does not need to start new line, cannot style height and width | HTML [div style="color: yellow] [strong] [em] [a] |
Block - styled inside css stylesheet. Starts new line, can style height and width | normal css stylesheet | |
inline-block - elements can appear next to each other and we can specify their dimensions using the width and height. | HTML [div class="rectangle"] [p]I am a rectangle![/p] [/div] [div class="rectangle"] [p]I am a rectangle![/p] [/div] [div class="rectangle"] [p]I am a rectangle![/p] [/div] CSS .rectangle { display: inline-block; width: 200px; height: 300px; } | |
Float | Commonly used for wrapping text around an image. Moving elements left or right for layout purposes is better suited for tools like CSS grid and flexbox. Values:
|
float: left; |
Clear | Specifies how elements should behave when they bump into each other on the page. Values:
|
clear: left; |
*replace [ and ] with < and > when applicable
width: 100%; position: fixed; top: 0; left: 0; padding: 20px; text-align: center;
width: 100%; position: fixed; bottom: 0; left: 0;
element | explanation | variations |
---|---|---|
font-family | property defines the typeface of an element.
5 types of web safe font family:
|
font-family: Monospace; |
font-size | Controls the size of text displayed.
Can be set based on Absolute size or Relative size. EG:
|
font-size: 40px; font-size: 1.2em; |
font-weight | defines how thin or thick text is displayed
|
font-weight: 700; font-weight: bold; |
font-style | define text style
|
font-style: italic; |
text-align | aligning the text to its container | left, center, right, justify |
background image | setting background of an element to an image | background-image: url('link'); |
Text transform | Transform whole text to uppercase | text-transform: uppercase; |
Letter spacing | Spacing between letters | letter-spacing: 2px; |
Word spacing | Spacing between words | word-spacing: 2px; |
Line height | Height between line. Value is in relative to font size | line-height: 1.4; |
Text decoration | To change text to underline | text-decoration: underline; |
element | explanation | variations |
---|---|---|
Color / Background-color | color refers to text colour while background-color refers to background colour.3 ways to write colours:
|
color: darkseagreencolor: #8FBC8Fbackground-color: rgb(143,188,143) |
Opacity | setting the transparency of an element | opacity: 50%; |
Hue Saturation Light | Hue is the first number. It refers to an angle on a color wheel. Red is 0 degrees, Green is 120 degrees, Blue is 240 degrees, and then back to Red at 360. Saturation refers to the intensity or puritycolorhe color. The saturation increases towards 100% as the color becomes richer. The saturation decreases towards 0% as the color becomes grayer. Lightness refers to how light or dark the color is. Halfway, or 50%, is normal lightness. Imagine a sliding dimmer on a light switch that starts halfway. Sliding the dimmer up towards 100% makes the color lighter, closer to white. Sliding the dimmer down towards 0% makes the color darker, closer to black. | color: hsl(120, 60%, 70%); |
Opacity and Alpha | To use opacity in the HSL color scheme, use hsla instead of hsl, and four values instead of three. Alpha (a) can be attached to HSL or RGB. Its in decimal, whereby 0.5 is half transparent. | color: hsla(34, 100%, 50%, 0.1); OR color: rgba(234, 45, 98, 0.33); |
A little unconventional, but still worth mentioning is how hex colors can also have an alpha value. By adding a two-digit hexadecimal value to the end of the six-digit representation (#52BC8280), or a one-digit hexadecimal value to the end of the three-digit representation (#F003), you can change the opacity of a hexadecimal color. Hex opacity ranges from 00 (transparent) to FF (opaque). Alpha can only be used with HSL, RGB, and hex colors; we cannot add the alpha value to name colors like green. There is, however, a named color keyword for zero opacity, transparent. It’s equivalent to rgba(0, 0, 0, 0), and it’s used like any other color keyword: color: transparent; | color: #52BC8280; OR color: #F003; OR color: rgba(0, 0, 0, 0); OR color: transparent; |
element | explanation | variations |
---|---|---|
Image styling | Image containing banana will have the attributes | img[src*='banana'] { height: 80px; } |
Link styling | Link containing Florence will have the attributes.more styling tips at Link Styling | a[href*='florence'] { color: lightgreen; } |
Important syntax | !important syntax is used to override any style | p {color: blue !important;} |
[table] [thead] [tr] [th]header row column 1[/th] [th]header row column 2[/th] [th]header row column 3[/th] [/tr] [/thead] [tbody] [tr] [td]row1 column 1[/td] [td]row1 column 2[/td] [td]row1 column 3[/td] [/tr] [tr] [td]row2 column 1[/td] [td]row2 column 2[/td] [td]row2 column 3[/td] [/tr] [/tbody] [tfoot] [tr] [td]footer column 1[/td] [td]footer column 2[/td] [td]footer column 3[/td] [/tr] [/tfoot] [/table] *replace [ and ] with < and >
[td colspan="2"] your content [/td] *replace [ and ] with < and >
[td rowspan="2"] your content [/td] *replace [ and ] with < and >
table { border: 3px solid black; border-collapse: collapse; /*to collapse border or else there will be 2 borders*/ font-family: Monospace; } th, td { border: 3px solid black; padding: 8px; }
Go to Google Font to look for code. Embed the code into [head] section EG: HTML [head] [link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap" rel="stylesheet"] [/head] *replace [ and ] with < and > CSS p { font-family: 'Roboto', sans-serif; }
Download and save font into folder, link it via CSS EG: CSS [beginning of CSS:] @font-face { font-family: 'GlegooBanner'; src: url('../fonts/Glegoo-Regular.woff2') format('woff2'), url('../fonts/Glegoo-Regular.woff') format('woff'), url('../fonts/Glegoo-Regular.ttf') format('truetype'); } [later part of CSS:] .banner p { font-family: 'GlegooBanner'; font-size: 20px; }
element | explanation | variations |
---|---|---|
Link - Tooltip and title attribute | When user hover their cursor over the link, a text will appear in a small box near the cursor. EG: Hover over here | HTML [a href="link" title="text that appear in small box when hover"] text that will change to a link [/a] |
Hover | Using CSS Pseudo class :hover attribute | CSS a { color: blue; } a:hover { color: orange; } |
Cursor | to change user curser when hovering on a link | CSS a { cursor: pointer; } |
Pseudo class | has to be this cascading sequence
|
CSS a:visited { color: yellow; } |
Buttons | HTML [button class="button"] Standard Buttons [/button] CSS .link-style.button { height: 50px; width: 200px; cursor: pointer; font-weight: 600; font-size: 15px; } | |
HTML [button class="skeuomorphic"] Skeuomorphic [/button] CSS .skeuomorphic { border: 2px solid #0c960c; border-radius: 5px; color: #F8F8F8; box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.2), 0px -2px 2px rgba(255, 255, 255, 0.5) inset, 0 2px 2px rgba(255, 255, 255, 0.8) inset; background: linear-gradient(#1D1, #0ebc0e); text-shadow: 0 -2px #0c960c; } .skeuomorphic:hover { box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.1), 0px -2px 2px rgba(255, 255, 255, 0.25) inset, 0 2px 2px rgba(255, 255, 255, 0.4) inset; background: #0ebc0e; background: linear-gradient(#0ebc0e, #0c960c); border-color: #064f06; } .skeuomorphic:active { margin-top: 2px; margin-bottom: -2px; box-shadow: 0px 2px 2px rgba(63, 63, 63, 0.1), 0px -2px 2px rgba(255, 255, 255, 0.25) inset, 0 2px 2px rgba(255, 255, 255, 0.4) inset; background: #0c960c; background: linear-gradient(#0c960c, #0ebc0e); } | ||
HTML [button class="flat"] Flat [/button] CSS .flat { background-color: #1D1; color: #fff; border: 2px solid #12dd23; border-radius: 10px; } .flat:hover { background-color: #0c960c; transition: background-color .15s, font-size .15s; font-size: 18px; } .flat:active { border-color: #fff; } |
*replace [ and ] with < and > when applicable
element | explanation |
---|---|
This is a box with shadow |
box-shadow: 10px 10px; |
This is a box with shadow with colour |
box-shadow: 10px 10px lightblue; |
This is a box with 5px blurred, lightblue box-shadow |
box-shadow: 10px 10px 5px lightblue; |
This is a box with blurred, light blue box-shadow with spread radius of 10px |
box-shadow: 10px 10px 5px 10px lightblue; |
The inset parameter changes the shadow from an outer shadow (outset) to an inner shadow.
This is a box with blurred, light blue, inset box-shadow |
box-shadow: 10px 10px 5px lightblue inset; |
Multiple shadow
This is a box with multiple shadow |
box-shadow: 5px 5px blue, 10px 10px red, 15px 15px green; |