<link rel="stylesheet" href="styles.css">
<style>p { color: "red"; }</style>
<p style="font-size: 200%;">Hello world</p>
<head>
<script src="jquery.min.js"></script>
</head>
<p>Hello World</p>
<script>$("p").css("color", "yellow");</script>
JS is executed immediately. If your JS is included at the top of a file, delay it until document load:<head>
<meta content="width=device-width,
initial-scale=1" name="viewport"/>
</head>
div { text-align: center; }
div { display: flex;
justify-content: center;
align-items: center; }
div.inner { margin: auto; }
div.outer { display: flex;
flex-direction: column;
justify-content: center;
align-items: center; }
div.inner { margin: auto; }
div.outer { display: flex; }
div.inner { flex-grow: 1; }
div.inner { flex: «grow» «shrink» «basis»; }
div.inner { flex: 1 1 auto; }
div.outer { display: flex;
flex-direction: column; }
div.inner { flex-grow: 1; }
div.outer { display: flex;
flex-wrap: wrap; }
div.inner { flex-grow: 1;
min-width: 80px; }
Wrapping flex creates sizing problems if you have more than two layers. Ex. fit-contents or min-content.
div.outer { position: relative; }
div.inner { position: absolute;
bottom: 5px;
right: 5px; }
div.red { position: relative;
left: 10px; }
div.inner { float: right; }
div.red { visibility: hidden; }
div.red { display: none; }
margin: «top» «right» «bottom» «left»;
margin: «top-and-bottom» «right-and-left»;
margin: «all-sides»;
padding: «top» «right» «bottom» «left»;
border: «top» «right» «bottom» «left» «style» [«color»];
div { box-sizing: content-box; /* default */
width: 2em;
height: 2em;
border: 0.5em solid red;
margin: 0.5em; }
div { box-sizing: border-box;
width: 2em;
height: 2em;
border: 0.5em solid red;
margin: 0.5em; }
span { font-size: 18pt; }
span { font-size: 24px; }
span { font-size: larger; }
span { font-family: "Lucida Sans", sans; }
span { font-weight: bold; }
span { font-style: italic; }
span { color: blue; }
span { text-decoration: underline; }
span { font-variant: small-caps; }
<form action="/do_thing.html" method="post">
<input type="hidden" name="key" value="value">
<input type="submit" value="Submit">
</form>
Now form elements are more often used as javascript input, or submitted via AJAX.
$("button").on("click", ...)
$("input[type=text]").on("input", ...)
$("textarea").val();
Transitions can change a property gradually.
a { transition-duration: 0.8s;
transition-property: opacity; }
a:hover { opacity: 10%; }
Animations change properties in a defined and continuous way.
animation: «duration» «name» «iteration-count» «direction»;
a { animation: glow 5s ease-in-out infinite alternate; }
@keyframes glow {
0% { color: red; } ...
100% { color: violet; }
}
Transforms and animations can be combined.
a:hover {
animation: shift-a-bit 0.5s ease-in-out infinite alternate;
}
@keyframes shift-a-bit {
0% { transform: rotate(0); }
100% { transform: rotate(5deg); }
}
div { column-count: 3; }
div.outer { column-count: 3; }
div.inner { break-inside: avoid-column; }
div.outer { columns: auto;
column-gap: 1em;
column-width: 6em; }
div.inner { break-inside: avoid-column; }
State | Abbreviation | Bird |
---|---|---|
Alabama | AL | Yellowhammer |
Alaska | AK | Willow ptarmigan |
Arizona | AZ | Cactus wren |
Arkansas | AR | Northern mockingbird |
table { border-collapse: collapse; }
td, th { border: 1px solid grey;
padding: 5px 10px; }
/* Browser typically bolds & centers th already */
th, td:first-child { font-weight: bold;
text-align: center;
background-color: #eaecf0; }
tr:nth-child(odd) { background-color: lightyellow; }
div.main-column {
font-size: 18px;
line-height: 24px; /* 1.6x font height */
max-width: 75em;
}
div.wrapper { display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
grid-auto-rows: minmax(10px, auto); }
div.red { grid-column: 1 / 3;
grid-row: 1; }
div.blue { grid-column: 2 / 4;
grid-row: 1 / 3; }
div.yellow { grid-column: 1 / 3;
grid-row: 2; }
I don't really know grid layout yet.
div { overflow: hidden; }
div { overflow: scroll; }
* All elements
#id Element with the given id
div All <div>s
.foo Elements with class "foo"
.foo.bar Elements with class "foo" and "bar"
div.foo <div>s with class "foo"
[attr] Elements with attribute "attr"
[attr=val] Elements with attribute "attr" set to "val"
a b b, a descendent of a
a < b b, a child of a
a, b a or b
a + b b immediately after a
a ~ b b immediately before a
:not(...) inverts selector
:has(...) cannot use yet
:hover. :visited
:first-child, :last-child, :only-child
:nth-child(n+3) 3rd, 4th, 5th child
:nth-child(even) 2nd, 4th, 6th child
::before, ::after
var script = document.createElement('script'); script.src = 'https://.../jquery.min.js'; document.appendChild(script);
Or, it's often easier to style elements directly. Jquery is especially good for this:
$("button").on("click", () => {
$("div").toggleClass("animated");
$("span.error").css("color", "red");
}