HTML Grid of widgets placed on top of content without obstructing it

This is a complex scenario that requires some patience to explain.

My goal is to create a grid of widgets that can be dynamically displayed and positioned relative to the main page content. These widgets need to interact with the user as well as the content beneath them, allowing for clicking and typing functionality.

The challenge I'm facing is finding a way to place these widgets inside a CSS grid container without obstructing the main content of the page. Despite trying different approaches such as using negative z-index values and adjusting other elements' z-index properties, I have not been successful in achieving the desired outcome.

I have included an image to illustrate the desired result, but I have yet to come up with a viable solution using HTML/CSS.

https://i.sstatic.net/Gb5y8.png

Answer №1

Why segregate widgets and content into separate containers if they do not visually intersect? It would be more efficient to place them together within the same container, allowing for dynamically displayed and relatively positioned elements.

If maintaining distinct containers is necessary, ensure that both left-side and right-side widgets have their own container, while the content is wrapped in a parent element. Positioning can then be determined using either grid or flex.

Answer №2

For those interested, @A Haworth provided the correct solution in the comments.

Below is a straightforward code snippet that effectively addresses my issue.

let count = 0;
function updateCount() {
  document.getElementById("display").innerHTML = `Count updated: ${count++}!`;
}
html {
  height: 100vh;
}

body {
  height: 100vh;
  display: flex;
  flex-direction: row;
  background: aqua;
  gap: 1rem;
}

nav {
  text-align: center;
  writing-mode: sideways-lr;
  background: gold;
  padding: 1rem;
}

main {
  flex: 1;
  background: teal;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
}

.wrapper {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repear(6, 1fr);
  gap: 1rem;
}

.item {
  background: orange;
  padding: 0.5rem;
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: all;
}

#item1 {
  grid-column: 1 / span 1;
  grid-row: 1 / span 1;
}

#item2 {
  grid-column: 1 / span 1;
  grid-row: 2 / span 4;
}

#item3 {
  grid-column: 5 / span 2;
  grid-row: 6 / span 1;
}

#item4 {
  grid-column: 6 / span 1;
  grid-row: 1 / span 1;
}

#item5 {
  grid-column: 3 / span 2;
  grid-row: 1 / span 1;
}
<html>
<body>
  <nav>This is the sidebar.</nav>
  <main>
  <div class="content">
    <h3>Content</h3>
    <article>
      <p id="text">Lorem ipsum dolor sit amet.</p>
      <button onclick="updateCount()">Click me!</button>
    </article>
  </div>;

  <div class="wrapper">
    <div id="item1" class="item">Item 1</div>
    <div id="item2" class="item">Item 2 <button>I'm clickable too!</button></div>
    <div id="item3" class="item">Item 3</div>
    <div id="item4" class="item">Item 4</div>
    <div id="item5" class="item">Item 5</div>
  </div>;
  </main>
</body>
</html>

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

Using Angular to pass parameters to a function

When passing a parameter to the getActiveId function in the ng-click <span class="col ion-ios7-heart-outline center" ng- click="getActiveId({{activeSlide.selected}})"> The value turns to zero in the controller, but it is passed correctly after tes ...

Analyzing all the <option> elements within a <select> tag with jQuery

I have a WordPress plugin in development and I am currently facing an issue with comparing user-input from an <input> element to a set of <option> elements within a <select> element. Here is my current approach: $('button#test_bu ...

Ways to dynamically adjust the size of a group of images in a limited space without any overflow, scrolling, or the use of media queries?

In my React app, I am receiving a variable number of square images from an API to display. These images come in dimensions of 200px, 512px, or 600px squares and have corresponding jackpot denominations and amounts underneath them with a title above. The di ...

How to centrally align text in list items using Bootstrap 5

Incorporating Bootstrap 5 into my project, I am facing a challenge with vertically aligning text in an li element. Despite trying various techniques mentioned in the Bootstrap documentation for middle/center alignment, none of them seem to be effective. I ...

Ways to stop the floating label from blending with the input field

Attempting to incorporate the Bootstrap Material design theme into my project, I have implemented a basic text input field using the code below: <div class="form-control-wrapper"> <input class="form-control empty" type="text"></input> ...

The background color property returns as blank, failing to update on the screen despite my attempt to assign a new value

In my current project, I'm utilizing a library called Colorthief to extract the dominant color of an image. This extracted color is then used to dynamically set the background color of three button elements. Here's how it works: var flag = docume ...

The confusion between <g:if> and <g:set> features in Grails is causing some issues

I am working with a gsp template that includes a variable. If this variable is true, I want to add an extra button; if it's false, nothing should happen. What could be causing my code to not work correctly? <g:set var="removeButton">{{ removeB ...

What is the best way to save longitude and latitude coordinates in a database using the <input> method?

Learn how to use HTML code <html> <body> <p>Press the button below to receive your coordinates.</p> <button onclick="getLocation()">Get Coordinates</button> <p id="demo"></p> <script> var x = doc ...

Styling didn't work on the default selected nav-link in my Vue 3 project using Bootstrap 5

My first visit here, please be patient. I am trying to emphasize the selected navigation link, and it seems to work fine for all except the first one (small). Even after selecting other options (medium or large) which do change color upon selection, when ...

Showing JSON Data in a Div Element

After successfully building the output for the JSON data and displaying it accordingly, I encountered a challenge trying to present the data in a straightforward DIV(preferably)/table container. Below is the code snippet: // Print out rows $prefix = &apo ...

Ways to correct misaligned Bootstrap column grid

I'm currently working on a form using Bootstrap 4, but I'm facing an issue where the columns are not aligning properly, causing unwanted space and reducing the size of the input boxes. Despite trying different Bootstrap CSS CDN codes in addition ...

Utilizing numerous script elements for three.js library

Today, I ventured into the world of three.js for the first time, along with exploring html and js in general. While experimenting with some example code, I encountered an issue. It seems that importing the three.js file from the script tag in my Main.js ...

When the page loads, does the browser automatically download mypic.jpg?

#feature1 { display: none; } #feature2 { background-image: url('mypic.jpg'); visibility: hidden; } <div id="feature1"> <span id="feature2"></span> </div> Kindly explain your response by providing a reason ...

Avoid allowing wysiwyg source code editor to alter the entirety of a website

Currently, I am implementing a WYSIWYG editor named "Jodit" on my website. This editor allows me to insert HTML code and add custom styling using the "!important" declaration, which can alter the CSS of the entire website. For example, you can visit Clic ...

Move the DIV element to a static section within the DOM

In my Vue app, I have implemented methods to dynamically move a DIV called 'toolbox' to different sections of the DOM. Currently, the DIV is positioned on the bottom right of the screen and remains static even when scrolling. My goal is to use t ...

Angular and JS do not have the functionality to toggle the split button

I have a question that seems similar to others I've seen, but I haven't found a solution yet. Can someone please review my code? In the component, I have {{$ctrl.init}} and {{$ctrl.people}} assigned. I am sure this assignment is correct because ...

Trimming the div tag from the bottom of the webpage

Currently utilizing bootstrap 4.0.0-beta.2 and encountering a CSS issue. In the specific layouthttps://i.sstatic.net/7WOGu.png Here is the HTML: <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" re ...

compressed vertical alignment bootstrap row

I am currently working with a code that displays articles within col-md-6 divs in a single row. Each article varies in height, and the visual aim is to create two columns of articles with similar total height. <div class="row"> <!-- FOR ARTIC ...

Clicking will open the link in both a new tab and the current tab

I'm looking to enable ng click functionality to work in both new tabs and the current tab. The URL is dynamically generated based on a certain condition. Here is the HTML: <a ng-href="{{myPathVariable }} " ng-click=" GoToThemes()" class="shift-l ...

Generating an HTML table that adjusts its size based on the paper dimensions chosen by the user

I am facing a challenge with my html table and print option on a webpage. Currently, users can easily print the table on an A4 page by default using the JavaScript print function. The table fits perfectly on the full size of the A4 page. However, I now h ...