Strategically placing an element under a canvas using HTML and CSS

The challenge I'm facing is positioning the experience section beneath the canvas and title elements. However, it seems like the experience section is overlapping the canvas. Despite trying to increase the left margin, I am still unable to resolve this issue.

@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');

*{
  margin:0;
  padding:0;
  box-sizing: border-box;
  background-color: black;
  font-family: 'Poppins', sans-serif;
}

body,html{
  overflow-x: hidden;
  font-family: Arial, Helvetica, sans-serif;
}


.webgl{
  position:absolute;

  
  
  
}


.title{
  color:white;
  z-index:1;
  
  margin-top: 300px;
  width:550px;

  font-size: 100px;
  font-weight: 800;
  outline: none;
  text-transform: uppercase;
  background: linear-gradient(135deg, #5335cf 0%, #de005e 25%, #f66e48 50%, #de005e 75%, #5335cf 100%);
  background-size: 400%;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; 
  animation: animate 10s linear infinite;
}

@keyframes animate {
  to{
    background-position: 400%;
  }
}

.page{
  z-index: 2;
  position:absolute;
}





header .header-contain{
  display: flex;

}

.experience-section {
  margin-top: 50px;
  padding: 20px;
  background-color: #f0f0f0;
  color: #333;
  margin-top: 400px;
  position:relative;
  
 
  
  

}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Suneet's Portfolio</title>
    
  </head>
  <body>
    
    
    <canvas class="webgl"></canvas>
    <div class="page">
      
      <h1 class="title">
          Welcome to Suneets Portfolio

          
      </h1>
      

      <section class="experience-section">
        <h2>Work Experience</h2>
        <div class="experience">
          <p>work</p>
          <p>work</p>
          
        </div>
      </section>

  </div>


  


    <script type="module" src="/main.js"></script>
  </body>
</html>

Despite my attempts at tweaking margins and positions, I have not been able to rectify the overlap between the experience section and the canvas.

Answer №1

After creating a Codepen using your code, I am currently exploring the issue you are facing.

There are some key concerns in your code:

  • You are utilizing a class to access the canvas, which is an unconventional approach. I want to confirm if this was intentional.
// Your current implementation
<canvas class="webgl"></canvas> // In HTML
document.getElementsByClassName('webgl')[0]; // Likely JavaScript code

// A typical method of doing it
<canvas id="webgl"></canvas> // HTML
document.getElementById('webgl'); // JS
  • You have duplicated the margin-top property within the .experience-section class.
.experience-section {
  margin-top: 50px;
  padding: 20px;
  background-color: #f0f0f0;
  color: #333;
  margin-top: 400px; /* Repeated declaration */
  position: relative;
}
  • Another concern is that you've set the background color to black for all elements.
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: black;
  font-family: 'Poppins', sans-serif;
}

I attempted to rectify these issues and achieve the desired outcome. Since no specific instructions were provided, I configured the canvas animation to display a rotating cube. If another effect was intended, please inform me.

Below is the code I modified:

HTML:

<head>
  <title>Suneet's Portfolio</title>
</head>

<body>
  <header class="header">
      <div class="title">
        <h1>Welcome to Suneets Portfolio</h1>
      </div>
    <canvas class="webgl" id="webgl"></canvas>
  </header>

  <section class="experience-section">
    <h2>Work Experience</h2>
    <div class="experience">
      <p>work</p>
      <p>work</p>
    </div>
  </section>
</body>

CSS:

* {
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
}

body,
html {
  overflow-x: hidden;
  font-family: Arial, Helvetica, sans-serif;
}

<!-- More CSS content here -->

If further assistance is needed, feel free to reach out. Thank you :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Significance of Unique Characters in MySQL and HTML

Seeking answers regarding character encoding intricacies within MySQL, Python, and HTML. The scenario entails a Python script extracting data from a website, populating a MySQL table. Subsequently, a PHP and HTML interface retrieves the data from the tabl ...

Error: HTML Array script malfunctioning due to undefined in_Array

TL;DR Script Assistance Needed Greetings, I've been grappling with getting this script to function properly using an array structure. However, I keep encountering the error message that in_Array is not defined. If anyone could kindly help me spot any ...

Webpack 4 Failing to Properly Render Select Tag

I am encountering an issue with a basic select element that is not displaying correctly due to Webpack. The screenshot below illustrates the final rendered page source, where the closing tag for the select element has been incorrectly positioned before the ...

Shifting shadow transition effect when hovering over the box

I'm attempting to create a slide animation effect with box-shadow over an image, where the black background moves from left to right. However, I am facing a strange blinking issue that I can't seem to resolve even after searching for solutions on ...

Apply a coating of white paint and add color to the border

I was struggling to create a form that has a white background color and a green border at the same time. I am using Bootstrap and it seems like I cannot apply both styles simultaneously. Here is the link to the form design I am trying to achieve: . Below ...

Utilizing AngularJs to differentiate between arrays and strings within an HTML template

I'm currently facing a challenge with creating a dynamic HTML template. In order to present data in a table, I need to distinguish between a regular String and an Array. Firstly, the HTML template is embedded within another template using the data-ng- ...

Trouble aligning Material UI data-table columns (table head) to center in React

I have a data table where I declare rows and columns as simple variables, making it difficult to style them using 'style={{textAlign: center}}'. I tried adding a CSS file, but it did not work with the Material UI table. I am unsure of how to proc ...

Can document flow easily be restored after using position:absolute, or is there a better alternative available?

I've been facing a challenge in finding an efficient way to center a div. I prefer clean html and avoid unnecessary divs just for centering purposes. To solve this, I opted to use position:absolute. Although I am aware that position:absolute disrupts ...

CSS - Divs failing to center using 'Auto: 0 Margin'

Attempting to design a menu bar using CSS, where the main buttons (blue divs) need to be centered within the navigation bar (orange divs) with equal spacing between each button. Despite trying margin: 0 auto, the alignment is not working as expected. Bel ...

The art of combining CSS3 gradients with background images

I've created a function that changes the parent element's background gradient when a checkbox's status is toggled. Check out the Lorem link to see it in action! Click here to view. However, I've encountered an issue with applying this ...

The counter up function pauses when scrolling and displays an error message

I keep getting this error whenever I try to scroll up towards my counter function -> "Uncaught TypeError: Cannot read property 'shift' of null at f (jquery.counterup.js:62)". Any suggestions on how to rectify this? Below is the code ...

I need help figuring out how to databind HTML elements in my data table

I have a column in my data table that includes the value: <strong>Hello World</strong> What is the best way to bind this data to my GridView so that it displays as bold text instead of showing the word "strong"? ...

Html2Canvas: Variability in PDF Image Output on Different Devices

Challenge Overview: I am facing discrepancies in the PDF images generated with Html2Canvas on various devices. While the design looks fine on my laptop, it shows inconsistencies on other devices like phones or different laptops. I suspect that these diffe ...

Selecting the incorrect label while hovering over a checkbox

I am using Bootstrap and encountering an issue with displaying checkboxes after clicking on an accordion element. While the first checkbox is displayed correctly, the checkboxes inside the accordion do not appear as expected. It is confusing to me why thi ...

Trigger a modal to open based on a specific condition

I have successfully implemented a default modal from Materialize, but now I am looking to add a conditional opening feature to it. In my application, there is a countdown timer and I want the modal to automatically appear when the countdown reaches a certa ...

specifying the input value pattern restriction in HTML5

Struggling to set a minimum and maximum value for an input text box. Despite my efforts, I haven't been able to make it work. How can I resolve this issue? The current pattern restricts values up to 10 but I need to allow values from 100 to 100000. Wh ...

Styling with CSS: Making a div's height fit within another div, including padding

Looking at the image, there seems to be a div with a width of 100% and no defined height. Instead, the height adjusts based on the content, with top and bottom padding in percentages. The issue arises when trying to place navigation buttons on the right si ...

Is it permissible to have <ul> tags within an H1 element?

I am curious about whether adding a list inside an H1 heading could cause any issues: <h1> <ul> <li><a href="...">some link</a></li> <li><a href="...">another link</a></li> <li>curre ...

Is there a way to implement a flex display in my react slider component?

Welcome to my custom slider design! <Slider {...customSettings}> <div style={{ 'display': 'flex !important' }}> <CustomToolComponent key={uniqueName} color={customColor} /> <UniqueTool key={uniqueName} co ...

Tips for rearranging the zOrder of an object using Threejs

Recently, I created a dynamic scene on the webgl platform featuring various 3D objects that can be manipulated by selection and movement. One feature I am trying to implement is drawing axes when an object is selected. While I have successfully drawn lines ...