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

Tips for detecting if text appears in bold on a webpage using Selenium

I came across a pdf document with the following content: <div class=**"cs6C976429"** style="width:671px;height:18px;line-height:17px;margin-top:98px;margin-left:94px;position:absolute;text-align:left;vertical-align:top;"> <nobr ...

Why isn't the parent div stretching alongside its child divs?

Take a look at this example: wthdesign.net/website/olaf&co/index.php I am currently working on creating a responsive layout, but I am struggling to figure out how to make the "#content" div stretch with its child div when there is more content than ex ...

Generating a fresh document in MongoDB using Mongoose, complete with references and assigned ObjectIDs

I've been attempting to use the mongoose create function in order to generate a new document with references, but I'm encountering an error when trying to provide objectIds for those refs. Despite my efforts to find a solution, I have been unsucc ...

Instructions for compiling node-sass within the present directory for specific files

In my project, the directory structure looks like this: - folder1 - styles1.scss - folder2 - styles2.scss I want to utilize node-sass through the command line to generate the following output: - folder1 - styles1.scss - styles1.css - folder2 ...

Adaptable/Responsive Layout

Thank you for taking the time to look at this post. I am currently working on gaining experience with html, CSS, and JavaScript in hopes of entering the Front End Developer field. Today, I encountered a few issues while working on this adaptive design. He ...

In pursuit of increased speed

When using $routeProvider in Angular, I have noticed that every time I navigate to a specific route, I see the following logs in the console: XHR finished loading: "http://localhost:8080/root/partials/view1.html". XHR finished loading: "http://localhost:8 ...

CSS animation for image hover effect in Revolution Slider

I'm currently facing an issue while using Revolution Slider. To better illustrate, I am referring to the original demo found at this link: . When browsing through the 'portfolio' tab, you'll notice that the images shrink and darken upo ...

Using Javascript to perform redirects within a Rails application

Currently working on a Facebook application using Rails. There are certain pages that require users to be logged in, otherwise they will be directed to a "login" page. I am unable to use redirect_to for this purpose as the redirection must be done through ...

Extract information from an HTML table into PHP

I have an HTML table that is generated dynamically and I am looking to extract the data from it using the POST method. Is there a way to accomplish this? Are there any alternative methods you would suggest for achieving this goal? Below is a basic example ...

What is the best way to insert data from a promise into MongoDB?

While attempting to integrate an array of JSON data from a different server into a MongoDB collection, I encountered the following error message: "Cannot create property '_id' on string". Even though I am passing in an array, it seems to be causi ...

"Sequelize will pause and wait for the loop to finish before executing the

As someone with a background in PHP, I'm finding the concept of callbacks a bit challenging to grasp. Essentially, I need to retrieve some rows and then iterate through them to compare against another model (in a different database). However, I want ...

Add data to a DataTable without the need to manually refresh the page

I am looking to dynamically append a DataTable on my webpage. The goal is to have a form that users can fill out multiple times and each time they submit their inputs, the results will be added to the DataTable for display. <table id="table" class="di ...

Development of a custom waterfall toolbar design using MUI framework

I've been working with a setup similar to the one found here: https://codesandbox.io/s/1op5mqq9oq By clicking on the checkboxes, the <Toolbar /> is displayed. As you scroll down the page, the <Toolbar /> remains fixed at the top and even ...

What is the best way to hide certain buttons from specific users in Angular using the If condition?

I am facing an issue with my array of blocked_users, where I need to hide certain buttons if a user is in the blocked_users list. Below is the code snippet from my angualr.component.html: <div *ngIf="!(userId in event.blocked_users)"> ...

Step-by-step guide on incorporating edit, update, and discard functionalities within an Angular Material table component (mat-table)

I am currently working on implementing edit, update, and discard functions in an angular material table. While I have been able to successfully edit and update the table row wise, I am struggling with how to discard table rows. If you would like to see wh ...

What is the best way to ensure all requests have been completed before proceeding?

Is there a way to ensure that the sortOrder function only runs once the getOrders function has fully completed its execution? I have considered using a callback, but I am unsure of how to implement it. Do you have any suggestions on how I can achieve this ...

Sorting Angular data using database queries

I'm currently setting up a blog for my website. Everything is running smoothly with the database, but I've run into an issue with the order of my posts - they are displayed in the opposite order that I want. The oldest post is showing at the top, ...

Error in Google reCaptcha 2: "a is null" occurs when grecaptcha.reset function is executed

I am currently working on a registration page that utilizes AJAX for validation on both the client and server sides. If the server side validation fails, the AJAX function returns the errors to the screen and tries to reset the reCAPTCHA using grecaptcha. ...

Is there a way for me to instruct jQuery to revert an element back to its initial value, prior to any dynamic alterations?

My question is regarding changing the content of a div using the `html()` method in JavaScript. I am currently working on implementing a "cancel" button and would like to revert the content back to its original value without having to completely reset it w ...

Exploring the Fusion of Strings and Arrays of Javascript Objects using jQuery and JSON

Trying to achieve a simple task, but not very proficient in jQuery so struggling to figure it out. Want to send JSON data to an ASP.NET Controller. Data includes strings and a list of objects. The code snippet would appear like this: View: $(document). ...