───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───
More HTML
idandclassare important attributes, mainly for styling.id→ typically for unique elements; elements are limited a singleidclass→ typically for general elements.
- Multiple
idandclassare space-delimited, such asrounded boldfor rounded & bold. idandclassattributes can be accessed through CSS or JS:
/* id="foo" */
#foo {
background: red;
}const foo = document.getElementById("foo"); // id="foo"
const bar = document.getElementsByClassName("bar"); // class="bar"Layout
- The layout of a website is essentially the website’s structure.
- A website should be intuitive; information should be accessible.
- Each page has a header, navigation bar, content, and footer.
- Within the content, there are different headings, paragraphs, etc.
Layouts make or break websites.
Introduction to CSS
- Through CSS, you can change how websites look
- Including size, color, margins, padding, etc.
- CSS is not uniformly implemented in browsers, mainly Internet Explorer
- Internet Explorer is dead anyways, there’s no reason to tailor your website for IE
- For example, to make all
h1elements blue, and set their font family to “Helvetica”:- For
classattributes, use.{class} - For
idattributes, use#{id}
- For
h1 {
color: blue;
font-family: "Helvetica";
}Inline Style
- You can use the
styleattribute on elements to add CSS to one specific element - Not recommended for more complex CSS → not syntax highlighted, and annoying to edit
<h1 style="color: red;">Hello</h1>Embedded Style
- It’s generally recommended to use External Style Sheets
- You can use CSS within a
styletag, but it leads to your page being messy
<style>
body {
background: black;
}
</style>External Style
- External style sheets are particularly helpful for making pages with the same style.
- If you’re using embedded CSS, and you change the color of something, you need to change it for all sites.
- To use an external stylesheet within your page, use a
linkelement:
<link rel="stylesheet" href="...">Style Priority
- Inline Style
- Embedded Style
- External Style
- Browser Default
- Additionally, the selector that is further down the CSS has priority
h1 {
color: blue;
font-size: 2em;
}
h1 {
color: red; /* this overrides the h1 color from blue */
}Comments
- You can add comments in CSS with the
/* comment */syntax - Make sure you include this comment for all of your CSS:
/*
Name: Your Name
Course: CSCI 1210
Asssignment: Lab x
Date: mm.dd.yyyy
Description: Learning CSS
*/Units of Measurements
Absolute Measurements
cm→ centimetersmm→ millimetersin→ inches (96px)px* → pixels-
- px are relative to the viewing device; for high-resolution screens, 1px implies multiple device pixels
Relative Lengths
em→ relative to font-sizerem→ relative to font-size of the root elementch→ relative to width of “0”vw→ relative to width of the viewportvh→ relative to height of the viewport%→ relative to parent element
Colors
hex→ hex representation- IE:
#RRGGBB,#RGB
- IE:
rgb→ red, green, blue (0–255)- IE:
rgb(255, 0, 0)
- IE:
rgba→ rgb + alpha/transparency- IE:
rgba(255, 0, 0, 0.5)
- IE:
hsl→ hue, saturation, lightness- IE:
hsl(360, 100%, 50%)
- IE:
hsla→ hsl + alpha- IE:
hsla(360, 100%, 50%, 0.5)
- IE:
currentcolor→ inherits from parent
Resources
───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───