Children elements do not inherit CSS properties from custom elements

In my Angular 5 project, I've come across an issue where CSS properties are not being inherited correctly from custom elements. Let's take a look at a custom component foo:

@Component({
  selector: 'foo',
  template: `
    <form>inside form</form>
    <div>inside form</div>
    outside
  `,
})
export class FooComponent { }

My intention is to change its opacity and max-height:

foo {
  opacity: 0.5;
  max-height: 0;
  overflow: hidden;
}

As it turns out, browsers like Firefox (59) seem to have issues properly inheriting these properties down to the child elements like form and div.

  • Firefox (59) correctly inherits opacity, but ignores max-height.
  • Chrome (64) doesn't inherit opacity and disregards max-height completely.

I have created a plunk showcasing the problem.

Could there be something peculiar about how custom elements handle CSS inheritance, or could this simply be browser bugs?

Answer №1

Both opacity and max-height are not properties that can be inherited from the parent element. It seems that this issue is related to the default inline display of your custom foo component, which may prevent applying a max-height, for example.

Try adding either

foo { display: block; }

or

foo { display: inline-block; }

and observe the results...

Answer №2

Experiment with incorporating the proper tags to implement CSS on specific elements. For example:

    bar.opacity-check form {
       opacity: 0.5;
    }

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

Tips on avoiding vertical overflow while permitting horizontal overflow

I have been working on implementing a zoom feature for images, along with displaying a set of thumbnail images at the bottom of the zoomed image. While the zoom functionality is working correctly, I am facing an issue with the overflow of the tiny images ...

Using Angular's ngFor directive to iterate over a collection based on a true

I am currently attempting to resolve the following condition: if the condition is true, display a button, otherwise hide the button. OfferMatching() { this.getmatchoffer.filter(obj => { debugger for (let i = 0; i < this.applicationJobList.length; i+ ...

Passing a JavaScript variable to PHP within an HTML document: Parsing data from Wikipedia

I am currently working on passing a JavaScript variable named $url to a PHP function in the same HTML file. The idea is that a user inputs a species into a textbox, and the Wikipedia API is called to check if the input matches a Wikipedia page. If a match ...

The tab contents are colliding and merging with each other, creating an overlap

I have created a code with two tabs that should appear when the tab header is clicked. However, there seems to be an issue where the content from the second tab is also previewing in the first tab when the page is loaded. Strangely, when I switch to the ...

Angular 2 partial static routing parameters with customizable features

Can an angular 2 routing configuration include a partial-static parameter? Currently, I am using a classic parameter setup like this: const routes: Routes = [ { path: ':type/fine.html', pathMatch: 'full', redirectTo: &ap ...

Angular and RxJS: Ensuring continuous interval execution in the event of an error

Every 10 seconds, I make a call to a RESTful service through an Angular service called "myservice" and a function called "foo." ngOnInit () { interval (10000).pipe (startWith (0), mergeMap (obs => this.myservice.foo ())).subscribe (resp = ...

JQuery .click Event doesn't center elements even with transform-origin adjustment

In the JSfiddle provided below, you can see that after a click event occurs, two span (block) elements rotate 45deg to form an "X". However, both elements are slightly shifted left, creating an off-center "X" relative to the parent's true center-origi ...

What is the best way to create a modal as a standalone component in Angular 2?

I recently discovered this library https://github.com/dougludlow/ng2-bs3-modal which allows me to create modals in Angular 2. For my application, I specifically need the modal to be in a separate component. Here is an example : a.component.html contains ...

"Utilizing CSS to Format Academic Publications in the Style of APA Guidelines

Is there a way to automatically format a list of academic papers for an updated page using CSS rules? I want to style published articles similar to the following example: https://i.stack.imgur.com/jO56V.png I don't want to manually enter &nbsp;& ...

Is it possible to utilize a single node_modules folder for multiple Angular 2/4 projects?

As I dive into the world of Angular, I've noticed that creating a new project can be time-consuming due to the 100MB "node_modules" folder that the CLI generates. The contents of this folder are repetitively consistent across projects, with few change ...

Navigating through different pages in Angular2 using Asp.net 4.5

I am in need of assistance. I recently switched back to using ASP.NET 4.5 from developing with Angular2 and ASP.NET Core, and I am facing a major issue with routing. When I was using ASP.NET Core, redirecting all 404 requests to index.html was simple with ...

How can I resolve the issue of <td> being repeatedly displayed five times instead of just twice in PHP?

Can someone assist me with fixing this for loop issue? I am trying to display controls next to each item in the row, but it is showing 5 sets of controls instead of just 2. <tbody> <?php //retrieve list of supplies $numOfRows = 0; $result = my ...

Unable to retrieve JSON data at this time

I am currently attempting to retrieve information from a JSON file using JQuery in my HTML code with the following script: $.getJSON( "en.json", function( data ) { console.log(data.age); }); Unfortunately, it doesn't seem to be working as expe ...

error: local server did not return any data

I am currently using PHP on a Linux machine. In my HTML code, I have set up an AJAX request to the local Apache server (check http://localhost), with the intention of displaying the data from the server on the screen. However, for some reason, nothing is b ...

Setting up Deployment Source in VSCODE: A Step-by-Step Guide

Looking for some guidance on deploying a basic Angular App to Azure. I have installed the necessary extensions, but when I right click on my AppService, I am not seeing the expected menu options. How can I configure the deployment source and enter the di ...

Having trouble navigating using router.navigate in the nativescript-tab-navigation template?

I have everything properly configured in my routes and no errors are popping up. When the initial tab is loaded, I am attempting to automatically switch to the second tab based on whether the user is logged in or not. tabs-routing.module.ts file: import ...

Adjust the alignment of items in the NavBar using BootStrap to ensure they

I'm having trouble centering the contents of my Nav Bar, and for some reason, everything seems to be left-aligned instead of centered. I haven't used float: left anywhere, so I'm not sure why it's not working as expected. The goal is ...

What is the best way to transfer weather data from a server to an HTML text area box?

Recently, I delved into the world of expressJS to set up a local server (localhost:3000). With the power of JavaScript (specifically in a file named app.js), I was able to send simple messages like "Hello World" to the browser. However, now I find myself f ...

Unable to assign to 'disabled' as it is not recognized as a valid attribute for 'app-button'

How to link the disabled property with my button component? I attempted to add 'disabled' to the HTML file where it should be recognized as an input in the button component (similar to how color and font color are recognized as inputs) ... but ...

Refreshing pages when routing with Angular 2 router

While delving into the world of Angular 2, I encountered a challenge with setting up a basic route. Every time I click on a link, the browser redirects to the new route but it seems like all the resources are being re-requested, which goes against the beha ...