Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
How to prevent CSS from being auto-appended to bottom of the head element

A group of volunteers has created a single/multi-select web component using StencilJS: https://github.com/NothingAG/adg-components

For this web component, Shadow DOM is not enabled so that developers can override/customise styles.

Now we want to hand it over to the client so they can use it in their project. They do it like this:

<script type="module" src="/build/adg-components.esm.js"></script>
<script nomodule src="/build/adg-components.js"></script>

<adg-combobox
  id="hobbies"
  name="hobbies"
  label="Please select your hobbies"
  optionslabel="Hobbies"
  multi="true"
  lang="de"
></adg-combobox>

What they experience though is that because the Shadow DOM is not enabled, the CSS is auto-attached to the very bottom of <head>, after any other styles:

enter image description here

This makes is very hard to override specific styles. Is there a way to prevent that? For example, it would make much more sense in our case that the styles are added right after <script type="module" src="/build/adg-components.esm.js"></script>, so any following <style> would take precedence.

One other workaround I can think of is to remove the styles altogether when running $ npm run build, and then let the client import the styles manually. But this doesn't feel like the right way to do it.

Any help is highly appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When the Shadow DOM is turned off, Stencil attaches the CSS to the head element, before the first link element.

Here is the relevant line of code that does this: https://github.com/ionic-team/stencil/blob/0cd139b6a0e17c6b0916d8b0fb3e943a523f4a2f/src/runtime/styles.ts#L79

So all you need to do is have at least one link element in the head and the CSS will be inserted in the correct document order so that you can override the styles.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!