Using an External Stylesheet with Polymer 2.0: A Step-by-Step Guide

I am still learning the ropes, so please bear with me...

Currently, I am attempting to customize a Polymer 2.0 custom element by utilizing an external stylesheet. However, for some reason, the styles from the external stylesheet are not being applied to the element.

This is the specific element that I am trying to style (web-app.html):

<link rel="import" href="../elements/Styles/style-web-app.html">

<dom-module id="web-app">
<template>
<div id="header-container" class="header-container">
<div id="logo">
<img id="Mono" class="logo" src="../img/mono_primary_white_RGB.png" 
height="75px" width="75px" />
</div>
<div id="header">
<h1 id="title">ICR</h1>
</div>
</div>
<div id="tabs">
<paper-tabs selected="{{selected}}">
<paper-tab name="Name">Name</paper-tab>
<paper-tab name="Type">Type</paper-tab>
<paper-tab name="Usages">Usages</paper-tab>
</paper-tabs>
</div>
</template>

Below is the code from the external Stylesheet file (style-web-app.html):

<dom-module id="style-web-app">
<template>
<style>
:host{
#title {
font-size: 30px;
/* text-align: center; */
width: 500px;
color: #FFFFFF;
}
#header-container, #tabs {
background-color: #01579B;
display: flex;
color: #FFFFFF;
}
#header {
display: inline-block;
}
}
</style>
</template>
</dom-module>

Can someone point out where it seems to be going off track?

TIA

Answer №1

Here's an example inspired by the Polymer 2.0 documentation that showcases how to import and apply external stylesheets within your elements using the include attribute in the <style>.

<!-- Define Your External Stylesheet -->
<dom-module id="my-style-module">
  <template>
    <style>
      p {
       color: red;
      }
      <!-- add more shared styles here! -->
    </style>
  </template>
</dom-module>

<!-- Import custom styling -->
<link rel="import" href="/bower_components/polymer/lib/elements/custom-style.html">
<link rel="import" href="my-style-module.html">
<dom-module>
 <template>
   <style include="my-style-module">
     <!-- style specific to custom element goes here! -->
   </style>

  <p>This is Paragraph A within the main DOM, styled in red.</p>
 </template>

 <script>
  //Custom element script here
 </script>
</dom-module>

In this scenario, you'd need to update the web-app.html file to incorporate the styles from style-web-app like so -

<style include="style-web-app">
         <!-- custom element style go here! -->
</style>

For a deeper dive into custom styling and utilizing external stylesheets, check out this resource.

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

Registration form input field in ReactJS keeps losing focus with every keystroke

Currently, I am in the process of creating a registration form for a website. I have implemented the handleChange function to alter the input text in the regData state. However, I am encountering an issue where every time I type something into an input fie ...

Framework designed to be compatible with Internet Explorer 7 for seamless

Is there a CSS framework that provides full support for IE7 without any issues? Specifically, something similar to Twitter Bootstrap but with guaranteed rounded corners and properly functioning tabs. I have experienced problems with the Popover plugin sp ...

Placing elements in Chrome compared to IE

I'm currently attempting to position elements in two rows using mathematical calculations. One of the elements, thumb_container, is a div that is absolutely positioned. Within this container, I am dynamically loading and appending image thumbnails usi ...

extracting data from checkbox to use in an angular function upon being selected

Currently, I am creating a list of checkboxes with distinct string values: heading, paragraph, list, table, visualtitle. I believe the current approach using (change)="onChange('heading', $event.target.checked) may not be the best way to han ...

horizontal Bootstrap Image Gallery

I'm having an issue with Bootstrap Thumbnails. Currently, my thumbnails are stacked vertically like this: img01. However, I want them to be in a horizontal layout. What should I do? This is my code: HTML: <div class="hrs" align="center"> ...

Removing a faded out div with Vanilla JavaScript

I am struggling with a JS transition issue. My goal is to have the div automatically removed once it reaches opacity 0. However, currently I need to move my mouse out of the div area for it to be removed. This is because of a mouseleave event listener that ...

Tips for positioning bootstrap-vue dropdown button items evenly

Can anyone help me align the dropdown button child items horizontally? I've tried customizing it with CSS but no luck. The control link can be found here Check out a sample on Js Fiddle here This is how I expect the design to look like: https://i.s ...

Maintain the aspect ratio of a div with CSS styling

Attempting to create a div while maintaining a 16:9 aspect ratio using CSS led me to conduct a Google search. Fortunately, I stumbled upon a helpful resource on Stack Overflow that detailed how to achieve this: How to maintain the aspect ratio. Excited to ...

Tips for smoothly switching from one SVG image to another

I am looking for a way to smoothly transition between two SVG images that are set as background images in a div. I am specifically interested in using CSS 3 transitions for this effect, but I am open to other solutions as well. Can you help me achieve th ...

Flexible DIV Grid Design with Overlapping Absolute Div Elements

My goal is to replicate the layout shown in this screenshot view screenshot here I want the layout to be responsive, with DIV B moving below DIV A when the screen is resized. DIV B is positioned absolutely to cover content and DIV C. Both DIV C and DIV ...

Ways to retrieve a particular class attribute within a less mixin

Having trouble with the .aClass? .aClass { width: 20px; height: 20px; } Looking to dynamically calculate a width value in .anotherClass based on the width of .aClass. .anotherClass { width: .aClass.width } Unfortunately, the code snippet above is no ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

The Twitter Bootstrap navbar dropdown is hidden behind the slider image

I am having an issue with my navbar built using Twitter Bootstrap 3.1.1. On iPhones and iPads, the dropdown menu is hiding behind the slider image. It is set to position absolute and has a z-index of 1000. Strangely, on desktop screens, everything works f ...

Guide to perfectly aligning a Bootstrap 4 toolbar

I've been trying to horizontally center a toolbar without success. Despite trying various solutions, nothing seems to work in bootstrap 4. The closest solution I found requires setting a width which doesn't really center the toolbar. Since the n ...

Rearrange the position of the default app name on the navigation bar

I have developed a MVC5 application and by default, the nav-bar displays the "application name", "home", "contact", etc. The application name is positioned on the left side of the screen, but I would like to move it to the center. How can I achieve that? ...

The Bootstrap navbar toggle is unresponsive and will not expand

I want to implement a Bootstrap navbar to expand the webpage when it is opened on a mobile phone. Below is the code snippet of how I have used Bootstrap in my HTML file: <html> <head> <link rel="stylesheet" href="https://cdn.jsdeliv ...

Customizing hyperlink styles with JavaScript on click

Hey there! I'm experimenting with something new. I've managed to change the background color of each link after it's clicked, but now I'm facing a challenge: How can I revert the original style when another link is clicked? Here's ...

Bootstrap accordion collapse feature not functioning properly

I'm just starting out with HTML/CSS and as I follow a few tutorials, I've encountered an issue when attempting to implement an accordion example from https://getbootstrap.com/docs/4.0/components/collapse/. It seems like the problem stems from the ...

Display sibling element upon hovering with AngularJS

Within a single view, I have multiple instances of repeated content elements. Each content element contains an anchor element. My goal is to toggle a class on a sibling element within that specific content element when a user hovers over the anchor. For c ...

Steps to deactivate a JavaScript function once the page has undergone a Page.IsPostBack event

My current setup involves a simple div with the display set to none. Upon page load, I use $("#MyDiv").show(); to display the div after a delay, allowing users to enter information into the form and submit it using an asp.net button. After submitting the ...