How to style core submenus in Firefox using Polymer?

This inquiry may have a broader scope than initially presented, however, I wanted to be as precise as possible. It seems challenging to utilize jsFiddle with Polymer due to the various imports required, but hopefully some code snippets will suffice.

Currently, I am working on customizing a core-menu structured like this:

<core-menu>
   <core-submenu label="First submenu">
     <core-item label="Test submenu item 1">
     <core-item label="Test submenu item 2">
     <core-item label="Test submenu item 3">
     <core-item label="Test submenu item 4">
   </core-submenu>
   <core-submenu label="Second submenu">
   </core-submenu>
</core-menu>

The challenge lies in styling the core-items within the submenu differently from the core-submenu itself. Selecting using core-submenu core-item works in Chrome, yet in Firefox it also selects the text "First submenu" and "Second submenu."

Upon inspecting the DOM structure in Firefox dev tools, it appears that Polymer is generating a nested structure similar to this:

<core-menu>
  <core-submenu>
    <core-item><div id="label">First submenu</div></core-item>
      <core-menu id="submenu">
        <core-item>Test submenu item 1</core-item>
        ...

In an attempt to address this issue, I tested #submenu core-item, which resolved one problem but created another. Chrome was unable to locate the items, as the polyfill did not assign the submenu id to the core-submenu element. After spending considerable time trying different selectors, I'm still seeking a solution that works seamlessly across both browsers. Any suggestions or guidance are appreciated.

Answer №1

I'm relieved that this selector managed to work, even though it may not be the most visually appealing solution.

core-submenu core-item:not(:only-of-type), #submenu core-item

Here's why it worked:

In Chrome

 <core-menu>
   <core-submenu>
     #shadow-root
       <core-item>Submenu 1</core-item>
     <core-item>Item 1</core-item>
     ...

In Firefox

 <core-menu>
   <core-submenu>
     <core-item>Submenu 1</core-item>
     <core-menu>
       <core-submenu>
         <core-item>Item 1</core-item>
         ...

The :not(:only-of-type) part of the selector excludes the chrome version's core-items inside the shadow DOM, while the #submenu core-item portion finds all submenu core-items in Firefox, including those in single item submenus.

While this solution adds a bit of technical debt, I hope that someone cleverer than me will come up with a more elegant fix. Time to tackle the rest of the styling selectors in the application...

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

Marquee is experiencing issues with incomplete scrolling

Hello everyone, I have been trying to implement a stock market ticker on my website. Initially, I used the marquee tag and it worked fine. Then I tried using simple scroll within the PHP UserCake user management system, but unfortunately, it is not working ...

Sneaky footer paired with a side panel

Trying to incorporate a sticky footer within the content area of a page that includes a full-height sidebar. Here is a preview of the page I'm currently working on: I have experience using in the past with success, utilizing methods involving percen ...

Inquiring about the rationale behind using `jquery.ui.all.css` specifically

I'm curious about the impact of jquery.ui.all.css on Tabs As soon as I remove it, <link rel="stylesheet" href="jquery/dev/themes/base/jquery.ui.all.css"> My tabs stop functioning. Here's my query: What exactly does the jquery.ui.all.cs ...

Utilizing the Invision prototype for embedding

They provided me with this code snippet <iframe width="424" height="916" src="//invis.io/U5574OIA3" frameborder="0" allowfullscreen></iframe> However, I am unsure of how to properly embed it. I attempted to insert the line into my website but ...

How can I bring a "floating" element above its sibling element without taking up space?

I have attempted setting all the parent elements to relative and this specific one to absolute, but it doesn't seem to be working. I'm quite puzzled at this point, here is the code snippet: <template> <div> <div @mouseover=" ...

Adaptable picture within a bootstrap container

I need help figuring out how to insert an image into a Bootstrap panel (see attached image): https://i.sstatic.net/BHQI9.jpg Here is the HTML Code I am using: <div class="panel panel-default col-md-10 col-md-offset-1"> <div class="panel-bod ...

Building a responsive image gallery modal using AJAX in Laravel platform

How can I fix the issue of the modal content briefly appearing when I load my page? I am trying to create an image gallery where a modal opens when an image is clicked. Here is the code in my view.blade.php: <script> $(".li-img").click(function ( ...

Stack div on top of div

It seems like I'm facing a simple problem that needs a solution. I have two container divs .topwrap{ position:relative; top:100px; background:#00C; } </i> and .lowerwrap{ position:relative; ...

Exploring the relationship between CSS z-index values and a canvas

http://jsfiddle.net/y2q3yLpj/ In my example, I tried setting the z-index of a canvas to 0 and the z-index of a div to 1. However, despite this configuration, the canvas appeared higher than the div. Surprisingly, when I set the z-index of the canvas to -1 ...

Unable to launch Firefox using Selenium WebDriver in Mocha with Node.js

Executing this simple test successfully opens the Firefox browser for me: var webdriver = require('selenium-webdriver'); var driver = new webdriver.Builder() .forBrowser('firefox') .build(); driver.get('http://www.go ...

Registered symbol appears as random characters in Internet Explorer web browser

When working on my HTML code, I encountered an issue with displaying a registered sign. While the entity code I used worked perfectly in Chrome, Internet Explorer showed an 'A' character before the sign. I tried various codes like -&#174; - ...

implementing a button's decrease and increase functionality in JavaScript

Whenever the button is clicked, it changes its color to red. Additionally, a counter increments with each click. However, I want the counter to be dynamic so that when the button is unclicked, the counter decreases as well. Unfortunately, I am facing diffi ...

A Firefox Browser View of a Next.js and Tailwind Website magnified for closer inspection

After creating a website using Next.js and Tailwind CSS, I noticed that the site is appearing zoomed in when viewed in Firefox. However, it looks fine in all other browsers. When I adjust the screen to 80%, the website displays correctly in Firefox. What ...

What methods can be used to keep divs from breaking onto separate lines?

My approach involves using divs to mimic a table structure. Below is the header section of this table: <div id="table-header"> <div id="header-row"> <div class="rate-rule-column s-boarder"> ...

What is the best way to eliminate excess elements from overflow:hidden?

Whenever I click on a modal, it changes my body to overflow:hidden. As a result, the scrollbar disappears and my page becomes unscrollable. Once I close the modal, my body reverts back to overflow:auto allowing the page to scroll again. These functionaliti ...

What is the best way to center align all elements using a wrapper in CSS grid?

I am working on designing a layout that looks like this: https://i.sstatic.net/jAaXL.jpg I have set the wrapper as a class and aim to center everything on the screen. Aside from the wrapper, I also want to make the text and form equal sizes. Here is th ...

Expand a div in navigation using JQuery

Check out this code snippet: .container { width: 150px; height: 100px; } .test { color: white; background-color: red; width: 100%; height: 25%; transition: height ease 1s; } .test:hover { height: 100%; } <div class="container"> ...

Adjust size of background image to fit within ie8 window dimensions

Currently, I'm facing an issue where a Drupal 7 module is used to load a background image, but CSS3 resizing is not supported in IE8. background-image: url('image.jpg'); background-size: cover; I have tried conventional methods like placin ...

none of the statements within the JavaScript function are being executed

Here is the code for a function called EVOLVE1: function EVOLVE1() { if(ATP >= evolveCost) { display('Your cell now has the ability to divide.'); display('Each new cell provides more ATP per respiration.'); ATP = ATP ...

Looking to effortlessly move and arrange items with ng2-drag-drop in Angular 2?

I have encountered a problem with the ng2-drag-drop library. I am trying to drag and drop items from one div to another, and then freely move the dropped item within the droppable area. One issue I'm facing is that when I drop my draggable item in th ...