Tips for creating responsive elements with a z-index of 1 in CSS

I have implemented the code provided in a codepen tutorial, but I replaced the world map image with a USA map. However, the dots are not responsive due to the z-index=1 specified on them.

I experimented with vh, vw, and percentages, yet when I resize my screen, the dots lose their position.

Can anyone assist me in making these dots responsive? My goal is to keep them fixed on the map regardless of its location.

Note: If there's an alternative method to achieve the same result, please suggest it.

Find the code on codepen below: HTML:

<div id="map">
  <div class="img-container">
      <img src="http://res.cloudinary.com/reddelicious/image/upload/v1496891721/map_no-dots_mptb8a.png" alt="Map">
  </div>
  <div id="dots">
      <div class="dot dot-1"></div>
      <div class="dot dot-2"></div>
      <div class="dot dot-3"></div>
      <div class="dot dot-4"></div>
      <div class="dot dot-5"></div>
      <div class="dot dot-6"></div>
      <div class="dot dot-7"></div>
      <div class="dot dot-8"></div>
      <div class="dot dot-9"></div>
      <div class="dot dot-10"></div>
      <div class="dot dot-11"></div>
      <div class="dot dot-12"></div>
      <div class="dot dot-13"></div>
      <div class="dot dot-14"></div>
      <div class="dot dot-15"></div>
      <div class="dot dot-16"></div>
      <div class="dot dot-17"></div>
      <div class="dot dot-18"></div>
      <div class="dot dot-19"></div>
      <div class="dot dot-20"></div>
      <div class="dot dot-21"></div>
  </div>

CSS:

/* Adapted from original pulsating dots by sharla */

@keyframes pulse {
  0% {box-shadow: 0px 0px 0px 0px rgba(52, 106, 180, 1);} 
  100% {box-shadow: 0px 0px 0px 7px rgba(52, 106, 180, 0.0);}
}

body {
    background-color: #111114;
}

img {
    width: 100%;
    max-width: 100%;
}

#map {
    position: relative;
    max-width: 1280px;
    margin: 0 auto;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    animation: pulse 1.5s infinite ease-out;
    background: #346ab4;
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    &:before {
        content: '';
        position: absolute;
        width: 3px;
        height: 3px;
        border-radius: 50%;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        margin: auto;
        background: rgba(255, 255, 255, 0.4);
    }
    &:nth-child(odd) { 
        animation: pulse 1.5s infinite ease-out 0.3s; 
    }
    
    /* Dot positions */
    
    @media (min-width: 768px) {
        width: 16px;
        height: 16px;

        &-1 { top: 34%; left: 14.5%; }
        &-2 { top: 43%; left: 15.5%; }
        &-3 { top: 51%; left: 20.5%; }
        &-4 { top: 61%; left: 27%; }
        &-5 { top: 68%; left: 29%; }
        &-6 { top: 79%; left: 29%; }
        &-7 { top: 39%; left: 47%; }
        &-8 { top: 30%; left: 46%; }
        &-9 { top: 27%; left: 47%; }
        &-10 { top: 31%; left: 47.5%; }
        &-11 { top: 34%; left: 48.5%; }
        &-12 { top: 47%; left: 53%; }
        &-13 { top: 56%; left: 47.5%; }
        &-14 { top: 78%; left: 53%; }
        &-15 { top: 56%; left: 76%; }
        &-16 { top: 62%; left: 78%; }
        &-17 { top: 41%; left: 79%; }
        &-18 { top: 52%; left: 70%; }
        &-19 { top: 26%; left: 51.5%; }
        &-20 { top: 39%; left: 27%; }
        &-21 { top: 82%; left: 88.5%; }

        @keyframes pulse {
            0% {box-shadow: 0px 0px 0px 0px rgba(52, 106, 180, 1);} 
            100% {box-shadow: 0px 0px 0px 10px rgba(52, 106, 180, 0.0);}
        }
    }
}

Answer №1

This solution appears to be working flawlessly in terms of responsiveness for me. Utilizing the vh unit is recommended, however, it seems like you may have overlooked removing the media attributes for height and width. If the dimensions are already tailored to the viewport, there's no need to adjust them within the media query.

@keyframes pulse {
  0% {box-shadow: 0px 0px 0px 0px rgba(52, 106, 180, 1);} 
  100% {box-shadow: 0px 0px 0px 7px rgba(52, 106, 180, 0.0);}
}

body {
    background-color: #111114;
}

img {
    width: 100%;
    max-width: 100%;
}

#map {
    position: relative;
    max-width: 1280px;
    margin: 0 auto;
}

.dot {
    width: 5vh;
    height: 5vh;
    border-radius: 50%;
    animation: pulse 1.5s infinite ease-out;
    background: #346ab4;
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    &:before {
        content: '';
        position: absolute;
        width: 1vh;
        height: 1vh;
        border-radius: 50%;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        margin: auto;
        background: rgba(255, 255, 255, 0.4);
    }
    &:nth-child(odd) { 
        animation: pulse 1.5s infinite ease-out 0.3s; 
    }
    &-1 { top: 34%; left: 14.5%; }
    &-2 { top: 43%; left: 15.5%; }
    &-3 { top: 51%; left: 20.5%; }
    &-4 { top: 61%; left: 27%; }
    &-5 { top: 68%; left: 29%; }
    &-6 { top: 79%; left: 29%; }
    &-7 { top: 39%; left: 47%; }
    &-8 { top: 30%; left: 46%; }
    &-9 { top: 27%; left: 47%; }
    &-10 { top: 31%; left: 47.5%; }
    &-11 { top: 34%; left: 48.5%; }
    &-12 { top: 47%; left: 53%; }
    &-13 { top: 56%; left: 47.5%; }
    &-14 { top: 78%; left: 53%; }
    &-15 { top: 56%; left: 76%; }
    &-16 { top: 62%; left: 78%; }
    &-17 { top: 41%; left: 79%; }
    &-18 { top: 52%; left: 70%; }
    &-19 { top: 26%; left: 51.5%; }
    &-20 { top: 39%; left: 27%; }
    &-21 { top: 82%; left: 88.5%; }

    @media (min-width: 768px) {
        @keyframes pulse {
            0% {box-shadow: 0px 0px 0px 0px rgba(52, 106, 180, 1);} 
            100% {box-shadow: 0px 0px 0px 10px rgba(52, 106, 180, 0.0);}
        }
    }
}

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

Converting JSON data into an HTML table

I'm struggling to convert a JSON object into an HTML table, but I can't seem to nail the format. DESIRED TABLE FORMAT: Last Year This Year Future Years 45423 36721 873409 CURRENT TABLE FORMAT: Last Year 45423 This ...

What are the steps to store my information in MongoDB with the help of Expressjs?

As a backend developer beginner, I am currently working with an array called Movie using expressJS. My goal is to save this array in a MongoDB database, specifically using Mongodb Atlas. Any help or guidance on this process would be greatly appreciated. I ...

Using AngularJS to bind to the 'src' property of an <img> tag

There is a table on my website with numerous rows, and each row contains a preview image that should appear in the top right corner when the mouse hovers over it. I attempted to insert an image tag with AngularJS binding for the URL in the src attribute l ...

The HTML element <p> is not spilling over onto a new line

Having trouble with text overflow in a kanban board? I've tried various CSS styling options like overflow-wrap: break-word;, word-wrap: break-word;, and hyphens: auto;, but nothing seems to work. Here's a preview. I'm using Vue.js, but I do ...

Attempting to remove an attribute or property in JavaScript will not yield the desired result

When I try to close the menu after opening it, the inline style won't get removed despite trying different methods. The CSS only has text properties for alignment and the class can-transform contains a media query. That's all the information I h ...

What causes the Invalid Form Body error to appear when using the Discord API?

While developing a Discord bot, I encountered an issue with creating a ping command. The error message received was as follows: (node:37584) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.footer.icon_url: Scheme "flashybot& ...

using jQuery to disable textarea input

I have this HTML code and I am using jQuery: <div><textarea style="height: 150px; width: 250px" name="myName" id="myId" class="text ui-widget-content ui-corner-all" > </textarea></div> Currently, I validate this field after the su ...

Pictures failing to load on both Chrome and Safari browsers

For some reason, the images on my app are not appearing in Chrome and Safari but show up fine in Firefox. If you try to open the image URL in a browser, it works perfectly. However, when embedded in the HTML document, the image appears broken. I also test ...

Encountering a GraphQL error during the compilation process

I've been following along with this informative tutorial: https://www.gatsbyjs.org/blog/2017-07-19-creating-a-blog-with-gatsby/ After completing all the steps, I encountered a GraphQL compile error: GraphQL Error There was an error while compiling y ...

Performing three consecutive Ajax requests in a Rails application

Recently, I developed a custom admin system for a local gym to manage payments, attendance, mailing, sales, and more. While everything is functioning smoothly, there seems to be an issue with the attendance feature. Occasionally, when taking attendance, an ...

When the JavaFX ComboBox drop-down opens in an upwards direction, the border appears incorrectly

While working with Java 8, I encountered an issue with the "javafx.scene.control.ComboBox" where if it doesn't have enough room below, it pops up instead. Strangely, the border styling of the elements still behaves as if it should pop down. Is there ...

I encountered the error message "TypeError: e is undefined" while attempting to make an ajax call

My goal is to showcase a website's content using file_get_contents in a PHP script and ajax on the front-end. I am able to display the entire page successfully, but when attempting to only show a certain number of images, I encounter the "TypeError: e ...

Tips for showing an inline <span> within <div> elements

Is there a way to showcase inline spans within a div element while ensuring they are displayed equally in size and space, based on the user's screen? And how can I ensure that these spans are positioned behind other div elements? body { width: au ...

Is there a method to update the res object following a couchbase DB call without encountering the error "Error: Can't set headers after they are sent"?

let express = require('express'); let searchRoute = express.Router(); searchRoute.get('/', function(req, res, next) { console.log('1'); databaseCall(function(error, result) { if (error) { res.sta ...

Incorporating Content-Disposition headers to enable the file to be both downloaded and opened

I'm having trouble allowing users to both view and download files on a web page. I've tried setting headers and using JavaScript, but can't seem to get it right. My goal is to have an HTML page with two links for each file - one to open in ...

Unable to update to the most recent version of React-Bootstrap

I'm facing an issue while trying to upgrade to the newest version of react-bootstrap. When I run: npm install --save react-bootstrap The following message appears: npm notice created a lockfile as package-lock.json. You should commit this file. npm ...

Functionality of setExtremes ceases to function post initial loading

Initially, the setExtremes function works fine for the chart. However, when I switch pages or reopen the chart with a new JSON file, the setExtremes function stops working and fails to update the min and max values. Any idea why this could be happening? yA ...

Tips for refreshing the page upon Geolocation request

I am working on a HTML5 project that requests geolocation from the user. Here is an image of what it looks like: My main query is: Is there a way to refresh the page automatically once the user grants permission to share their location? Are there any Jav ...

A JSON object received from an AJAX request is either null or empty

I recently deleted a previous question that I had posted because it was no longer relevant and there was another issue to address. The response provided below is very clear, more so than other responses, and I believe it will be beneficial for anyone else ...

error 404 when sending a xhr request in node and react js

I am currently developing a basic login page in React that needs to connect to a database through an AJAX call to a Node.js file. Here is the Node.js code I have implemented: var express=require('express'); var app=express(); var db=require(&ap ...