With just an hour of HTML and CSS experience under my belt, I have a much deeper understanding of programming languages like JavaScript. So please bear with me as I navigate through creating a p5 canvas that follows my CSS styling.
How can I achieve this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My website!</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="container">
<h1>My Website</h1>
<h2>It is all coming together.</h2>
<script type="text/javascript" src="p5.js"></script>
<script type="text/javascript" src="my_code.js"></script>
</div>
</body>
</html>
Here's a snippet of my CSS:
body {
background-image: url("matt-walsh-tVkdGtEe2C4-unsplash.jpg");
background-repeat: no-repeat;
background-size: cover;
}
.container {
background-color: hsla(0, 0%, 50%, 0.8);
height: auto;
width: fit-content;
padding: 0px 250px;
}
h1 {
text-shadow: -2px 0 black, 0 2px black, 2px 0 black, 0 -2px black;
font-size: 10vw;
font-family: Arial;
color: white;
text-align: center;
}
h2 {
text-shadow: -2px 0 black, 0 2px black, 2px 0 black, 0 -2px black;
font-size: 5vw;
font-family: Arial;
color: white;
text-align: center;
}
p {
font-family: Arial;
color: black;
text-align: left;
max-width: 200vw;
}
script {
alignment: center;
}
And to wrap things up, the setup and draw functions for the canvas:
function setup() {
createCanvas(400, 400);
}
function draw() {
if (mouseIsPressed) {
fill(0);
ellipse(mouseX, mouseY, 80, 80);
}
}
This creates the following page: https://i.sstatic.net/s5XKD.jpg