Updated 2026.07.14.c
<!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>Often used to make a card or article with multiple lines.
<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>Attributes:
src="https://mysite.com/video.mp4" = URL of the
videocontrols = a boolean, if this exists then show the
browser's native video controls.type="VALUE" = values can be video/webm,
video/mp4.autoplay = a boolean, if this exists then autoplay the
video when page loads.controlslist="value" = which controls to allow on the
video. Values include: nodownload,
nofullscreen, noremoteplayback. Ex:
controlslist="play nodownload". See https://wicg.github.io/controls-list/explainer.htmlcrossorigindisablepictureinpicturedisableremoteplaybackheight="100px"loading="value"loop = if this exists allows the video to play over and
over again.muted = if this exists the video starts as muted.poster="https://mysite.com/image.jpg" = an image to
show while the video is loading.preload="VALUE"In the below example the browser first tries to show a .webm video. If that doesn't work then it tries to show an mp4 video. If that doesn't work then an error message shows.
<video controls>
<source src="myvideo.webm" type="video/webm" />
<source src="myvideo.mp4" type="video/mp4" />
<p>ERROR: Your video doesn't support HTML video.</p>
</video>
More info at: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/video.
CSS colors (COLOR) can be specified in many ways:
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.
100vh means 100% of the viewport height.50vw means 50% of viewport width.1rem is the base type size of the HTML element. By
default 1rem is 16px, 2rem is
32px.em and use rem instead for
responsive websites. rem is a relative size.fr like
1fr or 2fr, which means fraction.Selectors are used to select HTML elements to apply the style to. CSS selectors are "greedy", that is they will select all the tags that match the selector syntax.
Here's 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. Match h1 or h2 or p.div.class1 {} = Compound selector. Select div with a
class of "class1"..class1.class2 {} = Select where the tag has both
classes. .button.primary {}p.mypara = Select all tags with this class.input[type="text"] {} = match only input boxes of type
text. Patterns: [attr] (if attribute exists?),
[attr=value] for exact match of attribute value,
[attr^=val] if attribute starts with,
[attr$=val] for if attribute ends with,
[attr*=val] if attribute contains val.:root {} or body {} = define default
settings for whole document.a:hover {} = change color or background of a link when
the mouse moves over it.input:focus {} if input box has focusbutton:active {} = if button is active.:focus = When a text field has focus you can change the
background-color to light yellow.:active =:checked = if a checkbox is checked.:indeterminate = if a radio button is neither checked
or unchecked, like when a page first loads.:required = when an input field is required.:optional = when an input field is not required.:link = Normally for <a> anchor
element.:visited = Normally for <a> anchor
element.:first-child = div:first-child {} finds
the first child of a div.:last-child = div:last-child {} finds the
last child of a div element.:nth-child(n) = apply to nth child like
div:nth-child(2) to apply style to second child of
<div>.:lang(COUNTRY_CODE1, COUNTRY_CODE2, COUNTRY_CODE3...) =
apply to elements with a specific language or lang="en"
element attribute. Ex: body:lang(en-US) {} See MDN.
The language codes are in BCP 47 language codes list. RFC 5646 is a
technical definition of how tags are structured and used: https://datatracker.ietf.org/doc/html/rfc5646, Language
codes, Language tag
lookup.:empty = select elements that have no content and no
children. Ex: p:empty {}.There are more pseudo-classes at W3Schools.
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.
Select class a or class b. Equivalent to .a, .b {}. Useful
when combining with other selectors. Select element with a class of a
and id of #id: :is(.a, #id) { }not(.class) = does not have the class
.class..demo :not(.pink) { } = choose items that have
.demo class but not .pink classes.: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 sentence 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.Select all tags with .myclass as the class.
.myclass1 {
}Item must have both classes:
.class1.class2 {
}#Myid {
color: blue;
}Old way:
.parent .child {
}With CSS nesting:
.parent {
color: blue;
.child {
color: red;
}
}Group selectors. Find .parent class with .child1 class OR .parent class with .child2 class.
.parent .child1, .parent .child2 {
}Import a font, image or something else. This imports a Google font package.
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Playfair:ital,opsz,wght@0,5..1200,300..900;1,5..1200,300..900&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');@media checks the size of the screen. It's useful for
setting limits on elements for different screen sizes. Inisde the
parentheses must be something to check, typically max-width
or width.
See https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media for more examples.
Examples
/* You can have multiple @media statements for different screen sizes. */
/* Styles if screen width < 480px. Instead of 'max-width' we can
also use 'width'. */
@media (max-width: 480px) {
.title {
font-size: 32px;
}
}
/* Styles if screen width < 768px */
@media (max-width: 768px) {
.title {
font-size: 36px;
}
}/* At the top level of your code */
/* "screen" means just use it for screen. Other values are: "all" and "print".
*/
@media screen and (width >= 900px) {
article {
padding: 1rem 3rem;
}
}
/* Nested within another conditional at-rule */
@supports (display: flex) {
@media screen and (width >= 900px) {
article {
display: flex;
}
}
}/* Define CSS variables */
:root {
--primary-color: #edf2fc;
--secondary-color: #212121;
}
/* Use CSS variables */
body {
background: var(--primary-color);
font-family: "Courier Prime", monospace;
}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:.
display: none | inline | block | inline-block | list-item | table | table-cell | table-row | flex | inline-flex | grid | inline-grid;flex: use with flex boxgrid: use width grid, different from flex box.display: flex;Example
<!DOCTYPE html>
<html lang="en">
<head>
<!-- comment -->
<title>CSS Anim ch 8 Menu</title>
<meta charset="UTF-8"> <!-- Required to show emojis -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="HTML, CSS, Javascript">
<meta name="description" content="Learn HTML">
<meta name="author" content="Me@somewhere.com">
<!-- link rel="stylesheet" href="style1.css" -->
<!-- See https://pastebin.com/jMG2ADx4 -->
<style>
* {
box-sizing: border-box;
margin: 8px;
}
body {
font-family: "Roboto", sans-serif;
background-color: rgb(209, 207, 207);
}
.title {
font-size: 16px;
}
.title:hover {
transition: all 0.5s ease-in-out;
background-color: rgb(239, 174, 174);
}
.menu {
display: flex;
}
.menu-link {
transition: all 0.5s ease-in-out;
}
.menu-link:hover {
transition: all 0.5s ease-in-out;
font-size: calc(100% + 4px);
background-color: yellow;
translate: translateY(-10px);
}
.image:hover {
transition: all 0.5s ease-in-out;
width: calc(200px + 10px);
}
</style>
</head>
<body>
<div class="title-wrapper">
<h1 class="title">The Website Title!</h1>
</div>
<div class="menu">
<div class="menu-item"><a href="#" class="menu-link">Home</a></div>
<div class="menu-item"><a href="#" class="menu-link">About Us</a></div>
<div class="menu-item"><a href="#" class="menu-link">Services</a></div>
<div class="menu-item"><a href="#" class="menu-link">Portfolio</a></div>
<div class="menu-item"><a href="#" class="menu-link">Contact Us</a></div>
</div>
<img src="https://i.pravatar.cc/300?img=63" width="200" alt="Old man in a hat" class="image">
<div>Real world challenge ch 8</div>
<div>My setup: VSC v1.119 on Windows 11 using Live Server extension in VSC. So I can test the web page in Live Server in another browser window. Live Server opens the web page in Google Chrome v150.0.7871. </div>
<div>For free test images see <a href="https://pravatar.cc">pravatar.cc</a>.</div>
</body>
<script>
</script>
</html>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;letter-spacing: 8px;border: BORDER-WIDTH BORDER-STYLE BORDER-COLOR|initial|inherit;border: 5px solid red;border-style, border-color, border-width.border-color: COLOR;border-color: red;border-style: VALUE; or
border-style: TOP/BOTTOM LEFT/RIGHT or
border-style: TOP LEFT/RIGHT BOTTOM or
border-style: TOP RIGHT BOTTOM LEFTborder-style: 5px solid red;VALUE: none, solid, dotted, dashed, double,
groove, ridge, inset, outset, hiddenborder-width and
border-color.border-width: VALUE; or
border-width: TOP/BOTTOM LEFT/RIGHT or
border-width: TOP LEFT/RIGHT BOTTOM or
border-width: TOP RIGHT BOTTOM LEFTborder-width: 5px;VALUE: thin, medium, thick, LENGTH (4px or
1.5rem)border-width and
border-color.border-top: VALUE BORDERSTYLE COLORThis 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%;
}box-shadow puts a box around the HTML tag.
box-shadow has more options than
text-shadow.
box-shadow: 6px 6px 5px -2px rgba(0,0,0,0.5)inset: if HOFFSET and VOFFSET are positive,
inset will put the shadow INSIDE the box in the upper
left.box-shadow: 5px 5px lightgreen;rgba(0,0,0,0.5) is a
small, nice gray shadow that fades nicely.This controls how long a transition takes, like
button:hover. Separate transition types with a comma.
Transition properties go in the non-normal selector like
button:hover per Reddit.
transition: [CSSPROPERTY] DURATION [TIMING_FUNCTION] [DELAY];
Affects all properties. Use Nms for milliseconds or
Ns for seconds, like 0.5s.transition: opacity 300ms; Affects only
opacity transitions.transition: [CSSPROPERTY] DURATION TIMINGFUNCTION DELAYall.
all is default. Properties affected by transition: many
like color, backgroud-color,
padding, transform, etc.transition: 200ms; for 200 milliseconds.
Transitions normally are 200-400ms.0.5s or 500ms.transition-property: font-size, color;ease, ease-in,
east-out, ease-in-out, linear
(default), step-start, step-end,
steps(4, end).steps(4,end) defines 4 steps to finish the transition.
This can make it look jumpy if that's the effect you want.Defines an animation at 0% to 100% at a minimum. Each keyframe
definition must have a different name. To have the animation go back and
forth use animation-direction: alternate;.
/* This is the minimum for @keyframs */
@keyframes pointdown { /* Define animation */
0% {
transform: translateY(0);
}
50% {
transform: translateY(16px);
}
100% { /* This state must match original for smooth animation */
transform: translateY(0);
}
}This is the combined shorthand syntax.
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. Or in seconds: 2s.TIMING_FUNCTION = same values as for CSS property
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;
alternate will run the animation forwards and backwords for
you. You do not have to define the animation in 3 steps where the last
step is the same as the starting step. Two steps will work.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 will run the animation forwards and backwards
automatically. alternate-reverse will reverse the animation
smoothly so it doesn't jump around to the starting point each time.animation-direction: DIRECTIONnormal which is default.
reverse. alternate to make it go back and
forth. alternate-reverse starts at end of keyframes.1s for 1 second, or 500ms for 500
milliseconds.animation-direction is alternate then the number of
times the animation plays is half of
animation-iteration-count.This can be changed via JS to start and stop an animation via a button click or another event.
ease, ease-in,
ease-out, east-in-out, linear,
step-start, step-end,
steps(4,end)animation-duration is infinite. p {
transform: translateY(16px);
animation: pointdown 1000ms; /* Specify animation here */
}
@keyframes pointdown { /* Define animation */
0% {
transform: translateY(0);
}
100% {
transform: translateY(16px);
}
}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. They can be used with filter: or
in other ways.
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">Calculate a new number or value.
.header {
font-size: calc(100% + 4px);
}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:
font-size: clamp(1.5rem, 5vw, 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)decimal,
decimal-leading-zero, lower-alpha,
upper-alpha, lower-latin,
upper-latin, lower-roman (Roman numbers like
i, ii, iii...), upper-roman. And symbols:
disc, circle, square. There are
more international numbering systems supported.counter-reset if you need to change the
counter. Also use with counter-set,
counter-increment, @counter-style which
defines a custom style.<style>
body {
counter-reset: section;
}
h2::before { /* Typical usage */
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>Using emoji as a counter style.
@counter-style thumbs {
system: cyclic;
symbols: "👍";
}
.mylist li::before {
content: counter(item, thumbs);
}Converts an image to grayscale. This could be useful, on hover the
image could turn to color. Enter a percent like 82%.
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>@media(CONDITIONAL)Check for screen size.
/* You can have multiple @media statements for different screen sizes. */
/* Styles if screen width < 480px */
@media (max-width: 480px) {
.title {
font-size: 32px;
}
}
/* Styles if screen width < 768px */
@media (max-width: 768px) {
.title {
font-size: 36px;
}
}Screen sizes:
@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. See these web pages:
@supports: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@supportsSyntax:
@supports (<supports-condition>) {
/* If the condition is true, use the CSS in this block. */
}
@supports (<supports-condition>) and (<supports-condition>) {
/* If both conditions are true, use the CSS in this block. */
}
/* OR operator */
@supports (transform-style: preserve) or (-moz-transform-style: preserve) {
}
/* Check to see if browser does not support a feature */
@supports not (transform-origin: 10em 10em 10em) {
}
@supports (display: grid) and (not (display: inline-grid)) {
}Test support via pseudo-elements.
@supports selector(::--webkit-scrollbar) {
color: green;
}Test for font supported.
@supports font-tech(color-COLRv1) {
body {
font-family: "Bungee Spice", fantasy;
}
}Does browser support a specific at-rule?
@supports at-rule(@keyframes) {
}Example:
/* 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;
}
}Two ways to check for nesting in a browser.
html {
.has-nesting {
display: block;
}
.no-nesting {
display: none;
}
}Or use @supports.
@supports (selector(&)) {
/* nesting parsing available */
}Responsive web design expands or contracts elements nicely when the screen size is changed, or when devices with a smaller screen are used. Use flexbox, css grid, @media queries to find screen size and apply different styles for different screen sizes.
Sources: https://www.youtube.com/watch?v=2IV08sP9m3U
padding: min(5em, 8%); to use
smallest value for padding.px, use
rem instead for font size. rem is a relative
font size and is the root element's font size.
font-size: 10vw; for 10% of viewport width.clamp(MINVAL, PREFERREDVAL, MAXVAL); Ex:
font-size: clamp(1.8rem, 5vw, 5rem);max-width: 100%; height: auto;
causes image to stretch in some cases.
<img src="images/sunset1.jpg" width="600" height="600">
No longer needed in Chrome v149+?aspect-ratio: 1/1;
for desktops, or aspect-ratio: 16 / 9; for landscape mode.
For smartphone in portraite mode use aspect-ratio: 9 / 16;
and images are stretched. Also use object-fit: contain; and
you will get empty spaces around the images. So use
object-fit: cover; and there will be no empty spaces.height: 100vh; to make element cover entire screen
height. But on Smartphone the height is bigger than the screen so the
user has to scroll down to see the whole element. CSS introduces a new
UOM called dvh or "dynamic viewport height". If we do
height: 100vh; height: 100dvh; the browser will just ignore
the method that doesn't work.inert HTML attribute so the
user does not accidentally click a hidden menu or item.<!DOCTYPE html>
<html lang="en">
<head>
<!-- comment -->
<title>Grid Test 1</title>
<meta charset="UTF-8"> <!-- Required to show emojis -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="HTML, CSS, Javascript">
<meta name="description" content="Learn HTML">
<meta name="author" content="Me@somewhere.com">
<!-- link rel="stylesheet" href="style1.css" -->
<!-- base href="https://mysite.com/base/" target="_blank" -->
<!-- Using Google fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: lightblue;
}
body {
min-height: 100dvh;
margin: 0;
display: grid;
place-items: center;
background: linear-gradient(135deg, #3730a3, #2563eb);
font-family: "Inter", sans-serif;
box-sizing: border-box;
}
.grid-container {
display: grid; /* Required for container */
grid-template-columns: 200px 200px 200px; /* Create columns */
grid-template-rows: 200px 200px 200px; /* Same but for rows */
gap: 1em; /* Gap between columns and rows */
}
.item {
padding: 2em;
background-color: var(--primary-color);
color: white;
text-align: center;
border-radius: 8px;
font-size: 2rem;
}
</style>
</head>
<body>
<!-- From CSS grid tutorial https://www.youtube.com/watch?v=JYfiaSKeYhE. A modern and responsive layout. -->
<div class="grid-container">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
<div class="item">Item 5</div>
<div class="item">Item 6</div>
<div class="item">Item 7</div>
<div class="item">Item 8</div>
<div class="item">Item 9</div>
</div>
<script src="scripttemplate.js"></script>
<script>
</script>
</body>
</html>
grid-template-columns: 1fr 1fr 1fr; /* Create columns */
then each column is 1 fraction wide.grid-template-columns: 1fr 1fr 2fr; /* Create columns */If you get your content from a database, for example, then the number
of search results can be different each time. Use
grid-auto-rows: which controls the size of each row.
style="grid-area: box-1" and change "box-1" to make each
item element name unique.This starts by having one parent container like .flex-parent, and
multiple child boxes with a class .flex-child. And in the class
.flex-parent set display: flex;.
<button>, style it
with: border-radius: 50%;.Sites where you can use HTML, CSS and JavaScript to test ideas.
<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