Coding - Intro To CSS
Coding - Intro To CSS
7. Displaying text
- Paragraph: <p></p>
- Contain a block of plain text
8. Styling text:
- Use tag within element: emphasize and strong
o Emphasize: give an italic text <em></em>
o Strong: give a bold text <strong></strong>
- Emphasize and strong tell the html how important the text is
9. Line break <br>
- Is a self closed tag
- Make a line in you text
- Put before the start word of the line
- 1 <br>=1 line
10. Unordered list <ul></ul>
- To create a list of item in no order
- <ul></ul> should not contain any raw text
- List items in bullet points
- Every single item stays between <li></li> tag, each item has 1 <li></li> tag
11. Ordered list
- Same as <ul></ul>, but items are listed in number points
- Coding element: <ol></ol>
12. Image
- Allows you to insert image into your tag
- Is a self-closing tag
- Code: <img src=”link”/> (basic)
- Special img alt: <img src=”link” alt=’content’/>
o Provide description in case of failure to load
o Help with visually impaired user
o Improve ranking webpage through SEO tool
13. Videos
- Tag: <video src=”link” width=”number” height=”number” controls> text </video>
HTML DOCUMENT STANDARD
- HTML = the skeleton of webpage; CSS (Cascading Style Sheets) = create style for HTML webpage.
- Modifying colors, font types, font sizes, shadows, images, element positioning..
- Extension: .css
o Save in a different file other than .html file
o Can write all the css code needed to style a page
1. Inline style
- Can write CSS code within HTML code using inline style
- Attribute: style=”..;” – always end with a semicolon “;” after every component
o Ex: <p style=”color: red;”>I’m learning to code!</p>
Result: I’m learning to code!
- A quick way of directly styling an HTML element
o Ex: <p style=”color: red; font-size: 20px;”>I’m learning to code!</p>
Result: I’m learning to code
2. The style tag <style></style>
- Css code can be written between <style></style> tag
- To use <style> tag, it must be placed inside of the <head> tag
- The code will follow the same rules with inline tag
o Ex: <head><style> p {color: red; font-size: 20px;} </style></head>
3. Linking the .css file
- Using <link> element to link html and css together. It is a self-closing tag
- Must be placed within the head of html file
- Attributes:
o Href: the address or path to css file
o Type: the type of document linking to (.css). should be set to text/css
o Rel: the relationship between html file and css file. Should be set to stylesheet.
Ex: <link href=”url link to file” type=”text/css” rel=”stylesheet”>
Ex: <link href=”./style.css” type=”text/css” rel=”stylesheet”> - link to file on
relative path
4. Tag name
- Using element’s tag name: css can select html element
- The syntax for selecting element:
o p{
}
o it will style the paragraph element
o any css properties will go inside curly braces to style the selected elements
ex: h1 {color: maroon;}
5. Class name:
- Css can also style element by attributes (class)
- Ex: <p class=”brand”>Sole Shoe Company</p>
In css: .brand {…}
- To select element for styling using attributes: .attribute name
- By running style over class name it will overrun any tag element – make the style more specific
to just one class, not the whole tag element
- Select multiple class:
o To add more than one class name to html element’s class attribute:
Write two css rules for styling
Ex: .green {color: green;} .bold {font-weight: bold;}
Include both of those classes on one html element, separated by a spacebar:
<h1 class=”green bold”>…</h1>
o In this way we can create unique style for element without writing custom class for
every style.
6. ID name:
- Styling multiple class is used to combine different style in one element (every style is separated
in one syntax. Classes are not unique.
- Styling id is used to create an unique style to one group of element. Ids are unique
- How to style id:
o Find an id to style. Ex: <h1 id=”large-title”>..</h1>
o Add id attribute on css. Ex: #large-title {..}
o Id tag in css always attached with #
- Id will override the style of tags and classes
7. The order of style priorities:
- Best practice: style elements first so that you can override if changes needed.
- Order of priorities: ID>classes>tags
8. Chaining selectors:
- Used when there is the same class on two different elements. Ex: class=”special” on <p> and
<h1>
- To select specific class on element: on css: name-of-element.class-name
o Ex: h1.special {..}
9. Styling nested elements
- Syntax: .class-name element-nested-in (space is given in between)
- It will style all the specific elements nested in a class
o Ex: .description h5 {..} will style all the h5 header in class description
- Order of priority: nested element styling>element styling
10. Important code - !important
- Can be applied to specific attributes instead of full rule
- Will override any style no matter how specific
- Syntax: p {color: blue !important;} .main p{color: red;}
o Will rule out any other styling effect
o Best to avoid and use at last resort
11. Multiple selector:
- Prevent repetitive code if both have same style
- Code: element , element {..}
o Ex: h1, .menu {font-family: Georgia;}
12. CSS structure:
- Ex: h1 {color: blue;} – CSS declaration
- Css declaration = Property + value
o Property: the property you want to style of an element
o Value: the value of property
13. Property:
- Font family
o The specified font must be installed on a user’s computer in order for display
o The default typeface: times new roman
o Limit the number of typeface: 2 to 3
Help page load faster
A good design
o Put in quotes if font name is more than 1 word
o Code: font-family: name of font;
o Web safe font: https://www.cssfontstack.com/
- Font size:
o Code: font-size: (number)px;
- Font weight:
o Code: font-weight: value;
o Value:
lighter<normal<bolder<bold
100 to 900
400: normal font-weight
700: bold font-weight
300: light font-weight
- Text align
o Code: text-align: value;
o Value: left, center, right
- Color:
o Foreground color (property: color): the color that an element appears in
o Background color (property: background-color): the color that an element is covered in
- Opacity:
o Measure how transparent an element is
o Value: 0 to 1
- Background image:
o Set the element’s background to display an image.
o Code: background-image: url(“link”);
o Or: link to a relative path: background-image: url(“folder/filename.jpg”)
1. The model:
- Comprises the set of properties defining part of an element taking up space on a webpage:
o Width and height: specifies the width and height of the content area
o Padding: the amount of space between the content area and the border
o Border: the thickness and style of border surrounding the content area and padding
o Margin: the amount of space between the border and outside edge of element
THE NEED TO CHANGE BOX MODEL: if you modify all the border, height, width, padding, the total
dimensions will be messed up. It will be difficult to accurately size a box, makes it difficult to position
and manage
COLOR IN CSS
CSS TYPOGRAPHY
1. Font Family
- Type of font: typeface or font family
- Property: font-family
- Note:
o The used font must be installed on a user’s computer
o The default typeface: times new roman
o Good practice: used between: 2 or 3
o When more than 1 word: used between double quotes
2. Font weight:
- Styling bold text with font-weight property:
- Property: font-weight
- Value:
o Default: normal
o Bold
3. Font-style:
- Property: font-style
- Value:
o Default: normal
o Italic
o Oblique
4. Word spacing:
- Increase the spacing between words in a body of text
o Note the difference with letter-spacing; the spacing between characters
- Property: word-spacing
- Value:
o Default: 0.25em
o Value (number)em
5. Letter spacing:
- Increasing the spacing between individual letters
- Technical tern: kerning
- Property: letter-spacing
- Value: (number)em
6. Text transform:
- Change the appearance of a text (uppercase, lowercase, capitalize)
- Property: text-transform
- Value:
o Uppercase
o Lowercase
o Capitalize
- Transform the original text in html to match the intention and readability
7. Text align
- Property: text-align
- Value:
o Left
o Center
o Right
8. Line height anatomy:
-
- Line-height property: modifies the leading of text
- Set how tall we want the line containing our text to be, regardless the height of the text
o Property: line-height
o Value:
A unitless number: ex: 1.2: an absolute value: will compute the line height as a
ratio of the font size
A number specified by unit: ex: 12px – can be any valid css unit (px, %, em, rem)
Preferred value: unitless ratio
9. Serif and sans serif
- Serif: fonts having extra details on the ends of each letter
- Sans serif: fonts do not have extra details on the end of each letter – straight, flat edges
10. Fallback fonts:
- Are pre-installed fonts that falls back if a font is not installed on a computer
- Syntax: font-family: “Garamond”, “Times”, serif;
o All determined elements: Garamond font
o If Garamond not available: times font
o If times not available: use any serif font pre-installed on computer
11. Linking font with google font:
- Go to fonts.google.com
- Search for the font needed
- Select that font with the plus sign
- Drop on the details line
- Embed: standard: to embed the selected fonts into a webpage, copy the code into the
<head></head> of html documents then you can use that
- To import into <style></style> tag: go to @import and copy the code
- To specify the link into css code: copy the css rules to font family
- You can choose all the customization for the font in the customize menu
THE CODE SYNTAX FOR HTML STYLEPAGE: use the <link> tag (selfclosed tag)
- A single linked font: <link href=”https://fonts.googleapis.com/css?family=Droid+Serif”
type=”text/css” rel=”stylesheet”>
- Multiple linked fonts: <link href=”https://fonts.googleapis.com/css?family=Droid+Serif|
Playfair+Display” type=”text/css” rel=”stylesheet”>
- Multiple linked fonts with weights and styles: <link href=”https://fonts.googleapis.com/css?
family=Droid+Serif:400,700,700i|Playfair+Display:400,700,900i” rel=”stylesheet”>
12. Font face
- Font face is another way to link non-user fonts that don’t require the use of <link> tag in html
document
- To load fonts with font face property: (@font-face)
o Enter the link into the url bar in the browser
o The browser will add the css rules.
o Focus on the rules that are directedly label as /*latin*/
o If doing the webpage in other language, focus on that as well
o Copy each of the css rules labeled in latin, and paste the rules from the browser to the
top of style.css
- To add a local font file by using @font-face
o Ex: @font-face {font-family: “Roboto”; src: url(fonts/Roboto.woff2) format(‘woff2’),
url(fonts/Roboto.woff) format(‘woff’), url(fonts/Roboto.tff) format(‘truetype’);}
o The main difference: the use of a relative filepath, instead of a web url
o Add a format for each file to specify which font to use. Since different browsers support
different font types files, so multiple font file options will support more browsers
- Use classes when you have elements that share many similar characteristics
- Use an id when you have one element that has unique characteristics
- Keep your code dry (don’t repeat yourself)
- Double check your syntax: always end declarations with semicolon, and check that properties
exist
SIZING ELEMENTS
***NOTE: ems and rems should be used to size text and dimensions on the page related to text size,
resulting in consistent layout based on text size. Else: use percentages.
- Background-position: can use these values: top – left – bottom – right to specify the edge you
want to position your background. The values defines an x/y coordinate, to place an item
relative to the edges of an element’s box. It can be defined using one or two values. If two
values are used, the first value represents the horizontal position and the second represents the
vertical position. If only one value is specified, the second value is assumed to be center.
o 1-value syntax could be:
Keyword value: center: which centers the image
One of the keyword values: top, left, bottom, right. This specifies an edge
against which to place the item. The other dimension is then set to 50%, so the
item is placed in the middle of the edge specified.
A length (pixel) or percentage (%). This specifies the X coordinate relative to the
left edge, with the Y coordinate set to 50%
o 2-value syntax: one defines X and the other defines Y
One of the keyword values: top, left, bottom, right. If left/right is given: this
defines X and the other given value defines Y. if top/bottom is given: this defines
Y and the other value defines X
A length (pixel) or percentage (%). If left/right is given: this value defines Y,
relative to the top edge. If top/bottom is given: this value defines X, relative to
the left edge.
- References: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
MEDIA QUERIES
CSS uses media queries to adapt a website’s content to different screen sizes. With media queries, css
can detect the size of the current screen and apply different css styles depending on the width of the
screen. Example:
-
- JavaScript methods are actions that can be performed on objects. A JavaScript method is a
property containing a function definition (follow camel casing)
- JavaScript operators are used to assign values, compare value, perform arithmetic operations
- JavaScript objects are standalone entities, with properties and type. (capital first letter)
1. Console
- Is a panel that displays important message
- Method: .log will print out all the information on the parenthesis
- Console is an object (a collection of data and actions)
o The log method will print to the object
o Code syntax: console.log(data);
2. Input comment:
- Single line comment:
o //comment over here: can use inline of the code
- Multiple line comment:
o /*comment*/: can use in between line of code
3. Data type in javascript
- Number: any kind of number
- String: any groups of characters. Must be in single or double quotes
- Boolean: there are only two values for this: true/false
- Null: represent the intentional absence of value. Keyword: null
- Undefined: denoted by undefined, also represent the absence of value – but different from
null
- Symbol
- Object: collections of related data
The first 6 data type: primitive data types
4. Arithmetic Operator
- Operator: a code/character that performs task in our code.
- Arithmetic operator: code:
o Add +
o Subtract -
o Multiply *
o Divide /
o Remainder/modulo %
5. String concatenation
- Use “+” to add two string (it will add exactly what is on two strings)
6. Properties
- When you introduce a new piece of data: the program will save it as an instance of data
type
- Every string has a property called length
o To check length: console.log(“hey”.length); //output: 5
- “.length” is one of the dot operator
7. Method:
- Are actions that we can perform
o The string method: are actions that we can perform with strings
- Use the dot operator to write a method
o Ex: console.log() = the log method on console object
- Example of string method:
o .toUpperCase() = returns all value/string in capital
o .startWith(“value”) = returns Boolean value (check to see if the string start with a
defined letter
o .trim() = remove all white space at the beginning and end of the string
8. Built-in object:
- Math object is one of the built in object for JavaScript
- Have method for object. Ex: Objectname.log() = print the string in object
- Method with Math object:
o .random() = pick a random number from 0 to 1
o .floor() = round down a decimal number to the nearest whole number
o .ceil() = round up a decimal number to the nearest whole number
o .isInteger() = check if a number is integer or not
VARIABLES
CONDITIONALS
1. If keyword:
- Code syntax: if (condition if true) {code block if true}
o (Condition if true): will evaluate with the value and print the output
2. Else statement:
- Code syntax: if (condition if true) {code block if true} else {code block if false}
3. Comparison operator:
- Less than: <
- Greater than: >
- Less than or equal to: <=
- Greater than or equal to: >=
- Equal to: === (compare the value and type of data)
- Not equal to: !==
A comparison must have:
o 2 values to be compared
o An operator to separate the value and compare them
4. Logical operator:
- Can use logical operators to add more complex logic
- 3 logical operators:
o The “and” op: && - 2 value must be true
o The “or” op: || - either 2 values true
o The “not” op: ! = will negates/reverse the value of Boolean
5. Truthy and falsy
- With non-boolean data type:
o If a variable has value: it is truthy (not falsy). So the condition inside the if syntax is
true
o If a variable has falsy value, which include:
0
Empty string “ “
Null (no value at all)
Undefined (lack of value)
NaN (Not a Number)
Then the condition inside the if syntax is falsy
o Ex: let a = 0;
If (a) {console.log(5);} else {console.log(6);} //output: 6
6. Truthy and falsy statement:
- Use to shorten conditionals (called: short-circuit evaluation)
- Ex: let defaultName;
If (username) {defaultName = username;} else {defaultName = “stranger”;}
o The code above can be shorten with truthy and falsy statement:
let defaultName = username || “stranger”;
o it will check the first value, if true then execute no code after, if false then use the
code after.
7. Tenary operator:
- Simplify if else condition with tenary operator:
- Code syntax: condition ? code block if true : code block if false;
8. Else if statement
- Else if statement will allow more than 2 possible outcomes
- “if” will be followed by “else if” and will be followed by else
- Code syntax:
o If (condition 1) {code block if condition 1 true}
Else if (condition 2) {code block if condition 1 false, condition 2 true}
Else if (condition 3) {code block if condition 2 false, condition 3 true}
…
Else {code block if all the conditions false}
9. Switch keyword
- Provide an alternate syntax for else if – increase readability and work environment
- Switch syntax:
o Switch (varName) {
Case /value to compare/ : code if true;
break;
case /value to compare/ : code if true;
break;
case /value to compare/ : code if true;
break;
…
Default : code if all false;
Break;
}
- /value to compare/: just the value, no condition code syntax
JAVASCRIPT: FUNCTION
Media breakpoints:
https://s3.amazonaws.com/codecademy-content/courses/freelance-1/unit-5/screen-sizes.png