Shadows in SVG do not mirror the shape of the element

I am currently working on implementing an SVG world map with interactive country selection. I am aiming to incorporate a shadow effect for a specific country upon the onmouseenter event. The functionality is mostly successful, but I have encountered an issue where shadows do not entirely align with the borders of certain countries. The desired outcome is to have the entire country surrounded by the shadow effect:https://i.sstatic.net/i52SO.png

For some countries, however, the shadow appears to be missing along the southern border as shown in this example: https://i.sstatic.net/ESkGW.png

What could be causing this discrepancy? I have experimented with different SVG files and consistently faced the same problem.

While I am utilizing the Rust Yew framework for development, I believe the issue lies more within SVG or CSS aspects that I may not be well-versed in. Below is a snippet of my CSS:

.shadow {
    filter: drop-shadow( 0px 0px 3px rgba(0, 0, 0, .7));
    z-index: 999;
}

This is how I render the map:

impl Country {
  fn toggle_highlight(e: MouseEvent, enable: bool) {
    let style = if enable {
      "#fcecec"
    } else {
      "#ececec"
    };
    let class = if enable {
      "country shadow"
    } else {
      "country"
    };
    e.target()
      .and_then(|t| t.dyn_into::<SvgElement>().ok())
      .map(|el| {
        el.set_attribute("fill", style)
          .expect("Unable to set style attribute for the country path");
        el.set_attribute("class", class)
          .expect("Unable to set class attribute for the country path");
      });
  }

  fn render(&self) -> Html {
    let onmouseenter = Callback::from(|e: MouseEvent| Country::toggle_highlight(e, true));
    let onmouseleave = Callback::from(|e: MouseEvent| Country::toggle_highlight(e, false));
    html! {
      <path class="country" id={self.id.clone()} name={self.name.clone()} d={self.path.clone()} onmouseenter={onmouseenter} onmouseleave={onmouseleave}></path>
    }
  }
}

...

html! {
  <svg baseprofile="tiny" fill="#ececec" stroke="black" viewBox="0 0 1500 1500"
       width="100%" height="100%" stroke-linecap="round" stroke-linejoin="round"
       stroke-width=".2" version="1.2" xmlns="http://www.w3.org/2000/svg"
       style="border: 1px solid red">
    { for build_countries_list().iter().map(|c| c.render()) }
  </svg>
}

Please advise if sharing the SVG data would be helpful in resolving this issue.

Answer №1

Shadows in the background are often hidden by outlines of other countries.

To bring the shadow into view, rearrange the element so that it is placed last in the DOM order.

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

Triad of Dots for Vertical Presentations

In the past, I successfully added 3 vertical dots to a slideshow by using absolute positioning and moving them into place. Then, I used JavaScript to cycle through the active class during the animation. However, when resizing down to smaller screen resolut ...

Material-UI's JSS does not adhere to the justify content property

Having trouble aligning elements in my React app using material-ui 1.0 and its JSS solutions. The code I've written below should center justify, but it's not working no matter how I configure it. I suspect there might be a naming issue since mat ...

Sizing Bootstrap Carousel Controls

Is there a way to adjust the size of controls in the bootstrap carousel using CSS? I'm working with Bootstrap 4 and have attempted the following, but it only seems to reposition them. .carousel-contol-prev { height: 26%; top: 33%; wid ...

Necessary CSS selector input equivalent in Reactive Forms

Is there a similar CSS method like input:required {CSS} to style all the reactive form fields in Angular that are set as required using Validators.required in their formControl? Or is there another approach to achieve this with CSS? ...

At times, the Kendo UI Tooltip may linger on screen longer than expected, failing to disappear as

I've been experimenting with this issue for quite some time now, but I'm stumped. Whenever I quickly move my mouse cursor over a series of links, occasionally a tooltip will linger on the screen even after the cursor has moved away from the link. ...

Changing knockoutJS foreach binding dynamically

I have a list of arrays known as table#1, table#2, ... table#10 and I want to be able to click on a table number and display the list items of that table in a panel. Here is a snippet of the code: The HTML part works fine. The only issue lies in this li ...

As a newcomer to Javascript, I am currently working on developing a CRUD-based application and could use some assistance with implementing the Edit functionality

I am currently in the process of developing a Javascript CRUD application that showcases data within an HTML Table. I have successfully implemented the Create, Read, and Delete functions. However, for the Edit function, I am looking to display the data in ...

What is the fastest way to add an email subscription form to my website without needing to configure a database?

Would it be possible to integrate a sign-up text box on our site for users interested in receiving launch notifications? Any suggestions on the most effective method to implement this feature? EDIT: Our current use of Prefinery has limitations as we cann ...

Collecting Information from the DOM to Append to an Array with JavaScript

My aim is to create a fully functional shopping cart using either vanilla JavaScript or jQuery. I'm uncertain if I'm approaching it the right way, but here's my plan: Firstly, I want to establish an array named cartItems to store all sho ...

Keep the table header in place while scrolling

I am currently working with Bootstrap V4 alpha 6 and Angular 5 to develop a table that includes a fixed header while scrolling. Unfortunately, I have been facing challenges in getting this functionality to work effectively. Note: The navbar is set to fixe ...

Can a jumbotron and navigation bar be permanently attached to the top of a screen?

Currently, I am in the process of constructing my website using Bootstrap and my goal is to ensure that the header and navigation bar remain fixed at the top of the page while the content below scrolls underneath. While I am aware that it is possible to fi ...

Can you explain the significance of the <%= %> HTML tag?

I've recently been tackling a project with Webpack. For those not familiar, Webpack is a bundler that combines all your files into one final product. One task I encountered was trying to insert one HTML file into another, similar to an import or requ ...

Transmitting an HTML snapshot to the server utilizing JavaScript on the client side

Can JavaScript be utilized to send the complete HTML code of a web page to the server? For instance, when a button is clicked, can the current HTML code of the webpage be sent back to the server? If so, how can this be accomplished? ...

How to Implement Multi Select Drag and Drop Feature in Angular 4?

Currently, I am implementing Angular 2 Drag-and-Drop from this library to enable the selection of list items using a drag and drop method. However, I have encountered issues with its functionality on touch devices and when attempting to perform multiple it ...

Including Previous & Next Buttons in Product Categories

I have set up the display of category products on the home page using the block below: {{block type="catalog/product_list" template="catalog/product/home_short.phtml" category_id="5" column_count="6"}}. I now want to include previous and next buttons to ...

Alter the browser's URI without having to reload the page

Is there a way to change the browser URL (or URI) without refreshing the page using HTML5 and HTML5Shiv for IE? For example, if I am currently on http://www.example.com but want to transition to http://www.example.com/4f6gt without the need for a full pa ...

Why is my bootstrap-enhanced website appearing unattractive on MSIE 8?

Check out my website at My website displays perfectly in browsers like Firefox, Chrome, Opera, and the Android Browser. However, when I viewed it on Internet Explorer 8 at my parent's house, it looked all messed up. How can I improve the compatibilit ...

Expandable Bootstrap collapse and accordion open horizontally, not vertically

I want to use Bootstrap collapse but I want to keep my div-s with the content beneath each link, mainly because that's how i need it to work on mobile (the menu is a column and that the content opens under each link). Unfortunately, on website I have ...

What is the best way to make a fixed div span the entire screen when it is placed within a fixed container

Currently, I have a container that is 100x100px in size and centered in the middle of my webpage. Inside this container, there is a nested div that is 100px tall, which I would like to stretch to the width of the entire screen. Does anyone know how I can ...

Django authentication ensures secure access for users on

What could be causing the issue with self.request.user.is_authenticated() not functioning correctly in this specific view? class ArticleDetailView(DetailView, CategoryListMixin): model = Article template_name = 'mainapp/article_detail.html&ap ...