Course: CSCI 1210
More HTML
id
andclass
are important attributes, mainly for styling.id
→ typically for unique elements; elements are limited a singleid
class
→ typically for general elements.
- Multiple
id
andclass
are space-delimited, such asrounded bold
for rounded & bold. id
andclass
attributes can be accessed through CSS or JS:
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
h1
elements blue, and set their font family to “Helvetica”:- For
class
attributes, use.{class}
- For
id
attributes, use#{id}
- For
Inline Style
- You can use the
style
attribute on elements to add CSS to one specific element - Not recommended for more complex CSS → not syntax highlighted, and annoying to edit
Embedded Style
- It’s generally recommended to use External Style Sheets
- You can use CSS within a
style
tag, but it leads to your page being messy
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
link
element:
Style Priority
- Inline Style
- Embedded Style
- External Style
- Browser Default
- Additionally, the selector that is further down the CSS has priority
Comments
- You can add comments in CSS with the
/* comment */
syntax - Make sure you include this comment for all of your 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