Okay so before starting I had absolutely no idea about HTML. I'd only used it to change the font color in
Obsidian using <font color="red">
.
I was inspired to learn by some awesome Neocities websites.
I decided to grab a book from my local library called Curso de Desarrollo Web: HTML, CSS y JavaScript. Edición 2021. and get on with it. As I read along, I try out the tags the book explains and also recreate the examples.
Here are my notes from each chapter of the book. They're not meant as a summary. I only take note of the stuff that is most interesting or surprising to me.
It's important to validate our HTML code for 3 reasons:
Even if our code is not completly valid, most browsers will render it fine. The end user will not notice.
We can validate our code with this page from the World Wide Web Consortium (W3C). There's also a VS Code extension that I'm using that does the same thing.
div
is one of the most common tags. It is used to divide HTML documents
into
different sections and then apply CSS styles to them. The're identified with ids.
Here is a list of styles presented as an unordered list (ul
).
code
We can apply styles to text directly in the HTML file.
Here's a neat example using color
,
font-size
, and text-align
.
We could also use a separate .css
file called CSS style sheet. If we do that we have to link it
to
our HTML file using link
in the header. But we'll do that later.
Create an example page as an exercise from the book
id
attributes to all HTML tags. This will
make
it easier to add CSS styles to them later on.
ñ
)
Paragraph on the right
Paragraph on the center
Paragraph on the left
Newlines
don't show up on the rendered webpage if they're enclosed in <p>
tags.
But we can force a line break
(like this)
using <br>.
<dfn>
for definitions, e.g. brain
rot <abbr>
for abbreviations, e.g. stan<cite> + <blockquote>
for quotes, e.g:"My boyfriend isn't gay, he's simply a good person"
Below I recreate the table in page 85 of the book:
Header of this huuge table | |||
---|---|---|---|
Subheader | |||
Period | Concept | Amount | Discount |
This month | Call identification | 12 € | 0 |
Individual Line | 14 € | 0 | |
City bonus | 10 € | 0 | |
Total: | 36 € | ||
Footer of this huuge table |
A description list? That's obscure HTML for sure. Does anyone actually use these?
We create them with the <form>
tag and have as attributes:
action, method, accept, enctype, id
. Here's an example.
The form above is a terrible example of how a form should be organized. Here's a better example!
To organize a forms we use:
This page is getting quite long... Why don't we add a table of contents to make navigation easier? To do that, we have to:
id
to the sections we want to link to (e.g. <h2 id="forms">
)
<a href="#forms">
)
Like this:
TitleAnother application of this is a ⬆️ Back to top button ⬆️.
Remote image:
Local image:
We use the <object>
tag to add audios and videos.With the <param>
tag
we
control autoplay, looping, and so on.
If we want to use media from other web pages we should cite the webpage and also use the embed code they give you.
witnesstestimony by GamingWithJumbo | License: Creative Commons 0(I embedded the audio because I am too lazy to download more files and also neocities doesn't let you upload audios and videos)
Semantic tags help structure webpages by giving meaning to the elements of the HTML file. If your don't know
which one to use just use a normal
<div>
tag. The most common elements are:
Listen to this awesome music! Here, turn it on whenever you feel like!
Pretty much the same as audios but we can define width and height as well.
Absolute units: Not used as much, not very dynamic. Examples include cm, in, mm, pt (points = 0.35 mm), pc ("picas" = 4.23mm)
Relative units: Calculated from another reference element. Used more often. Examples include em (width of letter M), ex (height of letter X), px, %
Usually people use px for margins, fills, and layers and % or em for font sizes.
Add comments to your CSS code /* Like this */
to avoid hating yourself in the future.
First part of a CSS rule. It determines to which elements the rule is applied to. There are two main types:
div h2 {font-size: 20px;}
only applies to h2
elements that are inside
a
div
tag.
p.my-text {color: white;}
only applies to p
elements with
class="my-text"
.
h1#intro {text-align: center;}
only applies to h1
elements with
id="intro"
.
[att=val]
: att
is exactly val
[att~=val]
: val
is at least one of the values of
att
[att$=val]
: att
ends with val
(e.g.
href$=".com"
)
[att^=val]
: att
starts with val
[att*=val]
: att
contains val
div > h2 {font-size: 20px;}
only applies to h2
elements that are direct children of a div
element.
div + h2 {font-size: 20px;}
only applies to
h2
elements that defined immediately after a div
element.
By default HTML elements inherit the properties of the elements they're inside. But if there's a more specific rule that will be used instead.
Some properties are not inheritable. For instance, links have default colors in browsers. Even if we add a
rule
that makes all text orange, links will still be blue. To change this behavior we can add
a {text-color: inherit;}
to force inheritance.
What if the same HTML element has conflicting rules? The most specific rule wins. In general ids are more specific than classes, and classes are more specific than regular HTML tags.
We can add !important
to a declaration to block a property. This means no other CSS rule
will
override this property. For example, if we write p {color: black !important}
all p
elements will be black no matter what.
🛑 Stop reading you nerd! Check out this demo page instead!🛑
Check out
Every HTML element is represented as a box. Using CSS we can modify the margin
,
background-img
, etc.
Some properties are shorthands that let us modify multiple properties at once. Examples include
margin
, border
, etc.
Classification of HTML elements:
<html>, <head>, <body>
<title>, <meta>, <link>
, etc.<div>, <form>, <h1-h6>, <table>
<a>, <img>, <input>, <select>
The CSS property position
can be:
(there's also inherit
but it wasn't included in
this awesome image)
Depending on the type, top, bottom, left, right
have a different meaning:
left: 20px;
= "20px to the
left of its normal position"Use to define the "depth" of an element.
According to this video your should not use px for
fonts. Use rem
instead, and em
for margin, padding, etc.
Stuff you can change with CSS:
We can also change how things look only when we hover over them or click them. For instance:
Hover over me! This is a normal link
Now hover over me! This is a
special link
We do this using pseudoclasses
Again, we can change pretty much everything when it comes to lists.
Because lists are so customizable, often people use them to make horizontal menus like this:
I'm too lazy to do a demo of this. Just know that the relevnt properties are:
text-overflow
→ how to clip the text if it's longer than its containerword-wrap / overflow-wrap
word-break
overflow
The difference between these properties is a bit confusing so just check out this article in case of doubt.
We can customize buttons too!
(CSS adapted from Frutiger Aero Archive)
display: flex
→ regular flexbox, behaves like a block elementdisplay: inline-flex
→ behaves like an inline elementCONTAINER PROPERTIES
justify-content
→ aligns items on the main axisalign-items
→ aligns items on the cross axisflex-wrap: wrap
, you unlock the
align-content
property.
align-content
controls how the rows of items are spaced along the cross axis.ITEM PROPERTIES
flex-grow
, flex-shrink
, and flex-basis
can be used individually —
but it's easier to just use the shorthand flex
and set it to 1
. That will pick
sensible defaults for the others.align-self
lets you override align-items
for one specific item.order
controls the order items appear in. By default, all items have order: 0
,
so they appear in HTML order. If you give one order: -1
it'll move first;
order: 1
moves it last.
You know what? I'm done now. Instead of reading this book I'm going to link to some resources I found to learn how flexbox works: