Positioning a dropdown menu on top of a Google Map in React with JavaScript: Best Practices

I've been attempting to place a dropdown menu at a specific location on my Google Map, specifically in the top right (or top left is also acceptable). Below is the current output I am seeing:

Here is the expected result:

Modifications

After trying margin-top: 100px;, the dropdown will move down. However, if I input margin-bottom: 500px;, the dropdown remains centered (where the origin is located). The same applies when using margin-left: 500px; to move the dropdown to the right, but using margin-right: 500px; does not allow the dropdown to move past the origin. It appears that only downward and leftward movements are permitted, not upward and rightward. See screenshots below:

The code snippet I am currently utilizing is as follows:

GoogleMap.js


import React from 'react';
import styled from 'styled-components';
import GoogleMapReact from 'google-map-react';
import { Card, CardImg, CardText, CardBody, CardTitle, /*CardSubtitle,*/ Button } from 'reactstrap';
import ShipTracker from '../components/ShipTracker';

const MapContainer = styled.div`
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 200px;
    grid-gap: 10px;
    height: 100vh;
    grid-template-areas: "google-map   sidebar" "ship-tracker sidebar";

    .google-map {
        background: #424242;
        grid-area: google-map;
        position: relative;
        height: 100%;
        width: 100%;
    }
    .map-sidebar {
        background: #9dc183;
        grid-area: sidebar;
    }
    .ship-tracker {
        grid-area: ship-tracker;
    }
`;

var expanded = false;

function showCheckboxes() {
// Function to show checkboxes
}

const BoatMap = () => (
    <div className="google-map">
        <GoogleMapReact
            bootstrapURLKeys={{ key: 'My_KEY' }}
            center={{
                lat: 42.4,
                lng: -71.1
            }}
            zoom={11}
        >
            {/* Insert components here */}
            <form>
                <div class="multiselect">
                    <div class="combo-companies" onClick={showCheckboxes}>
                        <select>
                            <option>Select an option</option>
                        </select>
                        <div class="overSelect" />
                    </div>
                    <div id="checkboxes">
                        <label for="one">
                            <input type="checkbox" id="CD" />Marker-1
                        </label>
                        <label for="two">
                            <input type="checkbox" id="DJ" />Marker-2
                        </label>
                        <label for="three">
                            <input type="checkbox" id="DT" />Marker-3
                        </label>
                    </div>
                </div>
            </form>
        </GoogleMapReact>
    </div>
);

GoogleMap.css

.combo-companies {
    position: absolute;
    height: 34px;
    width: 10%;
    font-size: 16px;
    border: 1px solid #111;
    border-radius: 3px;
    left: 15px;
    top: 15px;
    z-index: 2000;
}

.multiselect {
    width: 200px;
}

.selectBox {
    position: relative;
}

.selectBox select {
    width: 100%;
    font-weight: bold;
}

.overSelect {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
}

#checkboxes {
    display: none;
    border: 1px #dadada solid;
}

Steps Taken So Far:

1) Implemented CSS Grid Layout to define the positioning of the Google Map. Verified the layout based on documentation references to ensure correctness.

2) A potential issue might stem from the use of relative and absolute parameters on the components, as discussed in posts like this one and this. Although informative, the problem could not be pinpointed.

3) Progress has been made towards finding a solution, with additional insight gained from a helpful post such as this one. Unfortunately, the solution remained elusive.

Appreciate any guidance provided on resolving this issue.

Answer №1

For a solution, you can experiment with the code snippet below in GoogleMap.css:

.multiselect{
width: 200px;
position: absolute; /* Alternatively, attempt relative if the former does not yield desired results */
margin: 2vh 50vw auto auto;
}

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

In need of a solution for this peculiar problem with an html table and css. Let's

Encountering an unusual issue with my table content .table { position:absolute; top:12px; left:3px; width:87px; height:74px; } .table tr { vertical-align:middle; } .table td { text-align:center; padding:1px;color:#000000; font-siz ...

What steps can be taken to correct the SQL syntax in this particular scenario?

An issue has arisen where the code is expected to display the result of a LEFT JOIN on 3 tables, but it is not functioning as intended and throwing an error message. Reactjs: The code retrieves values and logs them using console.log. import React,{use ...

Processing - managing json replies

I am currently working with two Node.js servers (Server A and Server B), both utilizing Express.js. One of the nodes, Server A, is using Request (https://github.com/mikeal/request) to send a GET request to the other server: //Server A app.get('/:id& ...

CakePHP and Legacy Ajax Script Integration

I have an old script that I want to integrate into a cakephp application. The script uses $_POST and I'm not very experienced with this, so I need some assistance with the integration. This is what the script consists of: THE JAVASCRIPT: prototype ...

Struggling with displaying a PDF file from the local directory in a NextJS application

I've been facing trouble importing and displaying my resume, a local file, within a react component. The code import myResume from '../assets/pdfs/myResume.pdf' is resulting in the error: Error: Cannot find module '../assets/pdfs/myRes ...

How to send a PHP variable to Ajax and execute a corresponding PHP function in response

I have a set of database records that are being displayed in separate div elements on the page. Each record corresponds to a specific ID, with its information displayed inside the div. My goal is to create a delete button for each record that would allow ...

Exploring files within a Node.js module using npm

I'm currently in the process of developing a Node module and I want to give users the option to optionally require some files that are part of the module. For instance: var M = require('my-module'); var Foo = require('my-module/foo&apo ...

Assigning alphanumeric characters to the axis for identification purposes

review the code in index.html <!DOCTYPE html> <html> <head> <title>D3 test</title> <style> .grid .tick { stroke: lightgrey; opacity: 0.7; } .grid path { stroke-width: 0; } .ch ...

Deploying database to Docker container via Docker compose

Could you provide guidance on integrating a database with a docker container? The specific database I am using is MongoDB. Here are the docker compose settings that I am currently utilizing: version: '3' services: main_front_2: resta ...

Tips for enhancing query performance when it is taking 30 seconds to execute a query in MongoDb

When running a query using node and mongoose, it is taking over 30 seconds to execute. I suspect the issue may be related to looping. Can anyone provide guidance on how to improve performance? I am new to mongoose. companies .findB ...

Safari re-downloads background image when revisiting with jQuery CSS

Using jQuery to set a background-image on my website: $('.header-image').css('background-image', 'url(/img/image.jpg)'); However, upon returning to the page from Safari, the image is downloaded again, unlike Chrome and F ...

PHP: Communicating Data with JavaScript

What if my PHP script requires some time to complete its operations? How can I keep the client updated on the progress of the operation, such as during a file download where the estimated time and data size need to be communicated? In PHP, calculating all ...

Excessive greed in 2 column layout is causing left alignment issues

Check out the sample code here: http://jsfiddle.net/YUhgb/ HTML Markup <html> <body> <div class="left"></div> <div class="right"> <div class="container"> <div class="i ...

What is the best way to include a div element with a dynamic animation on a webpage?

I'm attempting to create a laser beam that can shoot enemies on the screen, much like in classic games such as Space Invaders or Galaga. However, I am encountering difficulties getting the laser to move when I click the button. Below is the code I hav ...

Control your thumbnails with the powerful iDangerous Swiper feature

Are you new to coding? I'm looking for help on linking thumbnail images to a swiper so that when a thumbnail is clicked, it moves the swiper-container to the corresponding slide. Any ideas or suggestions would be greatly appreciated! Here's an e ...

An Error with jQuery Autocomplete: "Callback is not Defined"

I am currently working on a jQuery script that involves autocomplete and selecting the correct value on the client side. Here is my functional code without the selected value (it displays all username available in my JSON): $(function() { $( "#us ...

Utilizing React Hooks efficiently with JSDoc annotations and destructuring arrays

Seeking guidance on how to properly JSDoc a React Typescript component that uses hooks, specifically when working with declared destructured arrays. Despite my efforts, I have not been able to find a solution that allows JSDoc to work seamlessly with destr ...

Encountered 'DatePickerProps<unknown>' error while attempting to develop a custom component using Material-UI and react-hook-form

Currently, I'm attempting to create a reusable component using MUI Datepicker and React Hook Form However, the parent component is throwing an error Type '{ control: Control<FieldValues, object>; name: string; }' is missing the follow ...

Sharing an image from an Ionic app to an Express.js server using Multer

I've attempted various methods to achieve this, but with no success. Here is my code for uploading an image using the Ionic framework (simply copy and paste it to run on Android). angular.module('starter.controllers', ['ngCordova' ...

What does Event.target.id return - the HTML id value or the HTML name value?

HTML Form Example: <form id="form-product-add" style="display: inline;"> <input name="csrf" type="hidden" value="<?= $this->csrf; ?>"> <input type="hidden" name="a ...