Issue with customizing pop-up styles in Mapbox-GL using Tailwind CSS within a N

I am struggling to achieve the desired style for this popup on hover example that I am adapting to a Vue (Nuxt) application utilizing Tailwind CSS. My suspicion is that the issue lies in how I am importing Mapbox's CSS file. However, I am uncertain about the correct import method or if it may be related to Tailwind. I have attempted importing in the following ways:

If I import like this:

<style scoped>
@import "mapbox-gl/dist/mapbox-gl.css";
</style>

The map appears like this: https://i.sstatic.net/6mjFu.png

If I import as follows:

import mapboxgl from "mapbox-gl";
import 'mapbox-gl/dist/mapbox-gl.css';

The map does not display at all.

Lastly, without importing any of Mapbox's CSS:

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

This is my map component:

<template>
  <div>
      <div id="map" class="w-full h-full"></div>
  </div>
</template>

<script>
import mapboxgl from "mapbox-gl";

export default {
  data() {
    return {
      access_token:
        "pk.eyJ1Ijoic2FtcGFvbGl0byIsImEiOiJja3c1Z2g1anowZ3Y1MnRwOGtieWRkdjNkIn0.wkW06MEvxRmyL3jfZYBTWA",
    };
  },
  mounted() {
    this.createMap();
  },
  methods: {
    createMap() {
      mapboxgl.accessToken = this.access_token;
      const map = new mapboxgl.Map({
        container: "map",
        style: 'mapbox://styles/mapbox/streets-v11',
        center: [-77.04, 38.907],
        zoom: 11.15
      });
      
      // Additional code for mapping features and popups
        
      // Add a layer showing the places.

        // Create a popup.

      // Event listeners for hovering over places on the map.
       
    },
  },
};
</script>

<style scoped>
/*
@import "mapbox-gl/dist/mapbox-gl.css";
*/
</style>

Answer №1

Resolved with the help of:

import 'mapbox-gl/dist/mapbox-gl.css';

Also, I adjusted the height of my map container to make it work :)

<div id="map" class="w-full h-96 mb-6"></div>

Answer №2

Encountered the same issue,

The most effective solution is to set the Map component to full screen height

const MapComponent = () => {

const style={
    container:`w-full h-screen mb-6`
}

useEffect(()=>{
    const map=new mapboxgl.Map({
        container:'map',
        style: 'YOUR STYLE URL',
        center:[77.634367, 12.961151],
        zoom:10,
    })
},[])

return <div className={style.container}  id='map'></div>

}

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

When refreshing data, duplicate the d3 graph

When I try to update my d3 graph after selecting a site from the dropdown menu, a new graph is generated and I can't figure out how to remove the old one. https://i.sstatic.net/R5BNE.png Below is the code within the script tags: <script> imp ...

Open the overflow div within a table data cell

My goal is to create a drag-and-drop schedule tool similar to Fullcalendar. I have decided to use a table layout with a rectangular div inside each TD cell to represent tasks. <table onDragEnd={dragend}> <tr> <th>0</th> ...

Adding Content Dynamically Before an HTML Element with CSS During Runtime

Let's say the HTML is defined as <div> <div class="runtime"> Some Important Text.Insert "Important" Before This </div> <div class="normal"> General Text </div> </div> Typically, t ...

"Enhance User Experience with Live Search Dropdown Feature in Bulma CSS Framework

Can I implement live search in a dropdown menu while using the Bulma CSS framework? In Bootstrap, there is a jQuery plugin called bootstrap-select that allows for live search functionality in dropdown menus. However, when I tried to use this plugin with B ...

Display additional links in Bootstrap navigation bar with a second level menu

Currently, I am integrating Bootstrap into an ASP.NET application using C#. Within this application, I have implemented a two-level menu system where certain options are available to users and others are only visible to administrators. The decision on whic ...

How can I align two responsive rows side by side in Bootstrap 3?

Utilizing Bootstrap 3, I'm faced with a challenge to achieve the layout depicted in the image. I have set up one row with two columns, positioned next to each other as shown; however, upon resizing to mobile view, I want the right column to drop below ...

Implementing jQuery form validation including checking for the strength of the password

My understanding of jQuery was quite basic until I began working on jQuery form validation with password strength check. I successfully completed the password strength check portion, but now I am unsure of how to enable the submit button once the condition ...

Can the URL be updated in Vue Router without navigating to a new page?

I am working on a Nuxt.js website and trying to implement a "Load more" button on the /catalog page. When clicking on the button, I want to load more products without navigating to a new URL like /catalog/page_2 (?page=2 is not an option). If I use $router ...

I can't understand why this question continues to linger, I just want to remove it

Is there a valid reason for this question to persist? I'm considering removing it. ...

Is there a way for me to display the image name at the bottom before uploading it, and have a new div created every time I upload an image?

Is there a way to display the image name at the bottom and have it create a new div every time an image is uploaded? I would appreciate any help with this... <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstra ...

Arrangement of Grid System in Horizontal Sequence

Can this specific order be achieved without the need for additional div elements? t1 t2 t3 d1 d2 d3 <dl> <dt>t1</dt> <dd>d1</dd> <dt>t2</dt> <dd>d2</dd> <dt>t3</dt> <dd>d3</d ...

Footer overflows content

My footer is getting overlapped by the slideshow on my webpage. I have already attempted to clear the previous DIV in the source code as per the usual recommendation: <div class="clear"></div><!-- /clear any floats --> However, this sol ...

Tips for creating a more seamless box transition within HTML

I've been searching for information on this topic, but I haven't been able to find a satisfactory answer. I want to create a div that displays "Contact Us" and when clicked, smoothly reveals a layer with input fields. I know I can use JavaScri ...

What is the best way to choose a child element that has been clicked using jQuery?

How can I make only the child of the clicked element slideToggle? I tried implementing a solution, but it ended up sliding all divs with the .description class. Can anyone provide some guidance? HTML: <div id="container"> <div class="row"> ...

Show varying HTML headers on the initial page as opposed to subsequent pages

Currently, I am utilizing an HTML to PDF Library known as Nreco for converting HTML Pages into PDF format. The task at hand involves implementing a consistent header on every page, with the exception of the first page that should display the Recipient Addr ...

The function _plugins_vuetify__WEBPACK_IMPORTED_MODULE_136__.default is not usable as a constructor

I have created a Vue application using vue cli 3 and incorporated Vuetify. To optimize the size of my bundle, I decided to modify the way Vuetify is imported: The versions I am working with are vuetify 1.5.5 and vue 3.7.0 import Vue from 'vue'; ...

Using CSS and Semantic UI CDN may encounter issues when testing in a localhost environment

My website's html code is structured as shown below, and the directory path is correct: <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> < ...

Alpha Screen and Shading Filter

Having trouble with CSS filters in IE8. I have a div with a gradient background that needs to have opacity set to 0, and when hovered over, the opacity should change to 1. Here's my code: #myDiv { filter: alpha(opacity=0); opacity: 0; background:rgba ...

Is there an issue with VUE npm run serve due to Tailwindcss being absent?

A few months back, I embarked on a project using Vue and incorporated Tailwind CSS by running the command (Vue add Tailwind). Recently, when attempting to create a new project with the default Vue3 template using the command vue create project and then na ...

Tips for properly configuring d3-zoom within a Vue application

I'm working with an SVG that displays seats in a venue, grouped by sectors. I want to implement a zoom-in effect when a seat is clicked, focusing on the seats within that sector. When another sector is clicked, it should zoom out and then zoom in on t ...