Updated 2026.06.18.a
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Proj 09, BEM</title>
<!-- <link rel="stylesheet" href="proj03boxxx.css"> -->
<style>
* {
box-sizing: border-box;
margin: 8px;
}
</style>
</head>
<body>
<script>
/* Script must be down here or the document will not load before JavaScript executes and you will get an error like "element does not exist" when getting an element by ID or class. */
</script>
</body>
</html><button id="" style="" onclick="">Button text</button>button.classname<tab>This is used now instead of strikethrough. A horizontal line will be shown in the center of the text.
<del>Delete this</del>Many items take a "length" as a value. Lengths can be absolute or
relative. Lengths are a number followed by a suffix. Ex:
50% or 2em or 2vw.
Selectors are used to select HTML elements. The basic syntax:
body {
background-color: grey;
}* {} = select all elements.p {} = select all p elements..classname {} = select by class nametagname {} = select all tags that match this tagname.
Ex: body {}#id {} = select the tag(s) with this ID..classname tagname {} = select the tagname inside a
certain class..parentclass .childclass {} = Select all childclass
elements inside parentclass..parent > .child {} = matches only direct children
of the class "parent".div + p {} = match only next sibling.div ~ p {} = match all following siblings.h1, h2, p {} = this CSS applies to all these tags, they
are grouped.div.class1 {} = Compound selector. Select div with a
class of "class1"..class1.class2 {} = Select where the tag has both
classes. .button.primary {} =input[type="text"] {} = match only input boxes of type
text. Patterns: [attr], [attr=value] for exact
match, [attr^=val] for starts with,
[attr$=val] for ends with, [attr*=val] for
contains val.a:hover {} = change color or background of a link when
the mouse moves over it.input:focus {} if input box has focusbutton:active {}There are many more.
li:first-child {} = for first child only.li:last-child {} = for last child only.li:nth-child(2) = for 2nd child only.::placeholder {} = change all input box placeholder
values.input:checked {} = for input box that is checked. For
check box?input:disabled {} = for disabled input box. Show the
user that it's disabled maybe with a gray background.input:valid {} = for valid text.:is(.a, .b) { } = group multiple selectors in one rule.
Math class a or class b. Equivalient to .a, .b {}. Useful
when combining with other selectors. Select element with a class of a
and id of #id: :is(.a, #id) { }:not(.a) { }:where(.a, .b. #id) { } = always has ZERO specificity.
Select match elements with class "a" or "b" or #id. In CSS the more
specific selector wins. Safe for base styles which will be overridden in
later CSS. Ex: .card :where(h1, p1, 1) {color:gray;}p::before {} = possibly to change content or add an
icon before someting.p::after {} = do something after the element.p::first-letter {} = possibly to capitalize first
letter of a sentense regardless of what the HTML looks like.p::first-line {} = make first line all small upper
case?div:has(p) {} = if a div has a
p child tag.:scope > .child {} = :scope refers to
current root element./* Define CSS variables */
:root {
--primary-color: #edf2fc;
--secondary-color: #212121;
}
/* Use CSS variables */
body {
background: var(--primary-color);
font-family: "Courier Prime", monospace;
}<button>, style it
with: border-radius: 50%;CSS commands come after the selector and after {} and are like "color:" which allows the user to specify a foreground color. A command has many values that can go with it and many value styles.
color: red;.The text, or foreground, color of an element.
color:#ff0033;color: white;color: rgba(255,128,128,0.15);. RGB colors have values 0 to
255. Alpha channel (a portion) value is 0.0 to 1.0.hsl().Same syntax and values as for color:.
100px70%100vw.Same as width:. This is the max width of the element
allowed if the browser window is resized.
width: with these differences:100vw for 100% of
viewport width.Same as max-width for this applies to height.
Adds content before or after or inside an element. Content is required for :after and :before but can be blank.
h2:after {
content: '*'; /* Use actual printable character */
}
li:before {
content: ' \00a7'; /* Use hex code */
}More entities:
font-family: "1+FONTNAMES, GENERIC_FONT_NAME"font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;GENERIC_FONT_NAME =
serif, sans-serif, monospace, system-ui, cursive, fantasy, math, ui-sans-serif, ui-serif, ui-monospace, ui-rounded.sans-serif is a generic font name, or "web safe font",
that most browsers support.'Times New Roman'.@import.font-size: medium|xx-small| x-small|small| large|x-large| xx-large|smaller| larger| LENGTH|PERCENT| initial|inherit;font-size: 10px;font-size: large;font-size: 120%;font-weight: normal| bold| bolder| lighter| NUMBER| initial| inherit;font-weight: 200;font-weight: bold;border: BORDER-WIDTH BORDER-STYLE BORDER-COLOR|initial|inherit;border: 5px solid red;border-style, border-color, border-width.This applies to INSIDE the element. Units that can be used: "auto", px, em, or percent.
padding: ALLSIDES; /* Inside margin */padding: TOPBOTTOM LEFTRIGHT;padding: TOP LEFTRIGHT BOTTOM;padding: TOP RIGHT BOTTOM LEFT;This applies to outside the element. Units that can be used: "auto", px, em, or percent. Margin adds spacing between elements on the page.
margin: TOP_BOTTOM_LEFT_RIGHT; /* Outside margin */ This
applies to all margins, top, bottom, left, and right.margin: TOPBOTTOM LEFTRIGHT;margin: TOP LEFTRIGHT BOTTOM;margin: TOP RIGHT BOTTOM LEFT;border-box: content-box|border-box;content-box the width of the element is the
width of the content only, it ignores the width of padding and
border.border-box the width of the element
INCLUDES the width of the content, padding and border.These act differently depending on the value of
position:.
/* Goes to top right of browser window. */
position: absolute;
top: 0;
right: 0; postion: absolute;
bottom: 0; /* Goes at bottom of browser window, good for headers and footers */ /* This item will not move when web page is scrolled. */
postion: fixed;
bottom: 0; /* Goes at bottom of browser window, good for footers */Value is 0% (not transparent at all) to 100% (completely transparent). For a :hover effect try 30%;
opacity: PERCENT;button:hover {
opacity: 30%;
}This controls how long a transition takes, like
button:hover.
transition: MS; Affects all properties.transition: opacity 300ms; Affects only
opacity transitions.transition: 200ms; for 200 milliseconds.
Transitions normally are 200-400ms.Defines an animation at 0% to 100% at a minimum.
@keyframes pointdown { /* Define animation */
0% {
transform: translateY(0);
}
100% {
transform: translateY(16px);
}
} p {
transform: translateY(16px);
animation: pointdown 1000ms; /* Specify animation here */
}
@keyframes pointdown { /* Define animation */
0% {
transform: translateY(0);
}
100% {
transform: translateY(16px);
}
}animation KEYFRAMENAME TIME(ms) TIMING_FUNCTION DELAY ITERATION-COUNT DIRECTION FILL-MODE PLAY-STATEKEYFRAMENAME = name given in the
@keyframes area.TIME = time in milliseconds to run the animation once.
Ex: 1000ms.TIMING_FUNCTION = same values as for
animation-timing-function like
linear| ease| ease-in| ease-out| ease-in-out| step-start| step-end| steps(int,start|end)| cubic-bezier(n,n,n,n)| initial| inherit;DELAY = delay before the animation starts like
2s.ITERATION_COUNT = animate this many times then stop. Ex
5.DIRECTION = which direction, choices are
normal| reverse| alternate| alternate-reverse| initial| inherit;FILL-MODE = a style when the animation is not playing.
Values are:
none| forwards| backwards| both| initial| inherit;PLAY-STATE = Use this property in a JavaScript to pause
an animation in the middle of a cycle. Values:
paused| running| initial| inherit;animation pointdown 1000ms This runs only
once.animation pointdown 1000ms infinitealternate-reverse will reverse the animation smoothly
so it doesn't jump around to the starting point each time.From https://www.w3schools.com/cssref/tryit.php?filename=trycss3_property1
<!DOCTYPE html>
<html>
<head>
<style>
@property --startColor {
syntax: "<color>";
initial-value: #EADEDB;
inherits: false;
}
@property --endColor {
syntax: "<color>";
initial-value: #BC70A4;
inherits: false;
}
.ex1 {
background: linear-gradient(var(--startColor), var(--endColor));
animation: gradient 3s linear infinite;
}
@keyframes gradient {
0%,
100% {
--startColor: #EADEDB;
--endColor: #BC70A4;
}
50% {
--startColor: #BC70A4;
--endColor: #BFD641;
}
}
#grad1 {
height: 200px;
}
</style>
</head>
<body>
<h1>The @property Rule</h1>
<div id="grad1" class="ex1">This is the gradient.</div>
</body>
</html>Functions can be used to calculate the length and put in values.
There are many built-in functions like calc(),
cos(), etc.
Link: https://www.w3schools.com/cssref/css_functions.php
Add blur to an element. 1px blur is plenty but the words are still readable. 2px makes text unreadable.
h1 {
filter: blur(2px);
}
#img1 {
filter: blur(2px);
}
#img2 {
filter: blur(6px);
}It works on images too:
<img class="blur" width="100px" src="https://countryflagsapi.netlify.app/flag/us.svg">
Makes the image darker (<100%) or brighter (>100%). 0% turns the image black.
<img width="100px" style="filter: brightness(50%);" src="https://countryflagsapi.netlify.app/flag/us.svg">cssproperty: clamp(MINSIZE, STARTSIZE, MAXSIZE)Responsive setting to set the <h1> element's
font-size to 5vw, but never smaller than 1.5rem or larger than 3rem.
Set the <div> element's font-size to 2.5vw, but
never smaller than 1rem or larger than 2rem. Also set the div container
to 50% wide, but never smaller than 200px or wider than 600px:
h1 {
font-size: clamp(1.5rem, 5vw, 3rem);
}
div {
border: 1px solid green;
padding: 10px;
font-size: clamp(1rem, 2.5vw, 2rem);
width: clamp(200px, 50%, 600px);
}You must define at least 2 steps.
background-image: conic-gradient(red, yellow, green);This allows you to put numbered section headers in your page.
counter(NAME, CNTRSTYLE)upper-roman<style>
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
</style>
<body>
<h2>conic-gradient()</h2>
<div id="conicgradient">This has a conic gradient.</div>
<h2>counter()</h2>
</body>Converts an image to grayscale. This could be useful, on hover the image could turn to color.
filter: grayscale(VALUE)60%.Inverts the colors of an image.
filter: invert(PERCENT); <img width="100px" style="filter: invert(100%);" src="https://countryflagsapi.netlify.app/flag/us.svg">
<img width="100px" style="filter: invert(30%);" src="https://countryflagsapi.netlify.app/flag/us.svg">@importImport another style sheet into yours.
<style>
@import '/dir/style01.css';
@import url('https://mysite.com/style01.css');
</style>@pageCustomize the printed version of the page.
@propertyDefine custom CSS properties directly in the stylesheet without having to run Javascript. This at-rule has data type checking and constraining, sets default values, and defines whether the property can inherit values or not.
@property --my-color {
syntax: "<color>";
inherits: true;
initial-value: lightgray;
}
body {
backgound-color: var(--my-color);
}@supportsTest whether a browser supports a CSS feature or not.
/* use this CSS if the browser does not support display: grid */
.container {
display: table;
width: 90%;
background-color: #2196F3;
padding: 10px;
}
/* use this CSS if the browser supports display: grid */
@supports (display: grid) {
.container {
display: grid;
grid: auto;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
}<script> tag. CSS supported: CSS, SCSS, SASS, PostCSS
(Stage 0+), Post CSS (Stage 3+), Tailwind CSS. https://jsfiddle.net/Show a flag on your web page.
THE END