I'm very new to CSS and HTML. Recently, I created a webpage using Jekyll with default theme called 'minima'. What I'm trying is to render some of the sketch that I wrote using p5.js. In particular, I want that the canvas of my sketch should be the page content area using full width of device (excluding the header and footer). Furthermore, it should be in the background of main content of website and should not conflict with it. For example,
This is a webpage and I want my p5.js sketch to use all the space betwen the two lines (header and footer). When I'm doing this by creating a div .sketch-container like
<main class="page-content" aria-label="Content">
<div class="sketch-container">
<script defer src="/Manoline-git.github.io/p5/Game of Life.js"></script>
</div>
<div class="wrapper">
{{ content }}
</div>
</main>
The sketch is coming after the main content of the page like this :
I tried several thing like putting z-index or moving the code around, but it just not working.
.sketch-container {
position: absolute;
top: 0;
left: 0;
z-index: 1; /* Ensure the sketch is on top of other content */
}
There might be a conflict in CSS, but I'm not sure. Can you please help me with this?
How to reproduce the above?
First setup the Jekyll (see documentation)
gem install bundler jekyll
jekyll new my-awesome-site
cd my-awesome-site
bundle exec jekyll serve
You can include the p5.js (can be downloaded from here) in your head.html
<script src="/assets/js/p5.js"></script>
Include the p5.js sketch file Game of Life.js given here. Use it on the page, such as on index.md
<script defer src="Game of Life.js"></script>
Please make sure the correct file location is given everywhere.


There are a number of variables that affect this issue:
createCanvas(400,400)then the size of your sketch will not be more than 400x400 regardless of your css.sketch-holderand its parent. In order to usez-indexproperty, both thesketch-holderand its parent must have thepositionproperty (parentpositioncan berelative, but must be defined)sketch-holderparent must have itsoverflow:hidden. Otherwise the sketch also covers the footer (or header).My ruby is fragile so could not install new site, but you can check out the results on my own site. Full site code here.
in
_layouts/so-demo-page.html:and the actual page in
so-demo.md:And in your p5.js sketch:
If you know the maximum height of your web page, then you can use that instead of the maximum height. You can also play with the positioning if you want to focus on the center of the sketch more than the
bottomortop.Good luck!