Issue: Angular 6 - Changing background color of HTML element not reflected in component

I'm facing an issue with my login page where I can't seem to change the background color. While I was able to successfully change the background color of the app-login element (the name of my login component) by adding

:host {
      display: block;
      background-color: blue;
}

in my SCSS file, as suggested here.

However, only the background of the component element is changing color. The rest of the page remains white. I tried inspecting and changing the background color of the HTML element in the browser inspector. I added background-color: blue; to the html{} tag.

Even after replicating this in my .scss file, it didn't work. I attempted using !important but no luck so far.

Below is a snippet from my login.component.scss file:

:host {
    display: block;
    background-color: blue;
  }
html{
    background-color: blue !important; // this doesn't work
}
.card-container.card {
    max-width: 400px;
    padding: 50px 60px;
}

.card {
    background-color: #F7F7F7;
    padding: 20px 25px 30px;
    margin: 0 auto 25px;
    margin-top: 220px; 
}

Answer №1

As stated in the angular documentation at https://angular.io/guide/component-styles

"The styles defined in the @Component metadata only affect the template of that specific component."

This indicates that any styles added to your login.component.scss file will only impact that particular component.

If you wish to utilize

html{
    background-color: blue !important;
}

You should include it in a global styles file (by default, src/styles.scss).

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

Is there a way to create a sunken shadow effect on just one side of an

Is it possible to make the shadow appear only on one side (Top) using CSS? I've tried multiple solutions, but I always end up with a shadow on all sides. This is what I have attempted: .box-container{ width:100%; height: 80px; padding:10px ...

"Transitioning from Angualrjs to Angular with the help of ng-upgrade

I need assistance with migrating my AngularJS application to Angular. Currently, I am following the Angular tutorial available at https://angular.io/guide/upgrade. Here is a snippet from my angular app.module: import { NgModule } from '@angular/core ...

CSS design element for creating unique corner shapes

Is there a way to create this shape using only CSS? I'm having trouble getting the middle white square perfectly centered. How can I achieve this? https://i.sstatic.net/Z9Cfb.png This is my current code: <div style="position:absolute; top:20px ...

What methods does a browser use to identify SCSS files?

While exploring this html template in Chrome's inspection tool, I was amazed to see that the browser was able to detect the scss files instead of the compiled css version. To investigate further, I pressed Ctrl+U to view the page source, hoping to fin ...

Styling tables within HTML emails for Gmail and then utilizing PHPMailer to send the emails

I've been racking my brain over this for hours with no luck! Objective: Implementing inline styles for table, td, th, p elements in an HTML email intended for Gmail using PHPMailer. Challenge: Inline styles not being rendered HTML Snippet: <sec ...

Looping through Angular variables within a component

As soon as I update the value of a property within a component's class that is being used in a loop, the value reverts back to its original state. This behavior does not occur when the component is used in isolation, without being part of an *ngFor lo ...

Unable to Switch Navbar State in Angular with Bootstrap 4

Unable to toggle the navbar when resizing to a mobile screen in Angular 4 using Bootstrap 4. It has been included in the angular CLI in script and styles, along with the necessary node modules from Bootstrap. Is there something missing in the code provided ...

Complete page browsing experience

Interactive Vertical Full Page Slider Concept I am interested in developing an interactive full-page slider that moves vertically instead of scrolling. This project would allow users to slide between page divs using the mousewheel. I am pursuing this ide ...

How to Modify Boolean Value in Angular 4 from a Different Component

Utilizing Booleans and a userRights.service to determine whether a navigation point should be displayed or hidden. The goal is to verify the user's rights upon login and then set the corresponding variables for navigation to either true or false. Thi ...

Using Responsive Design with Bootstrap and Media Queries

As a beginner in front-end development, I have recently learned about media queries and their functionality. Having previously studied Bootstrap, I can't help but wonder if media queries are actually necessary. After all, Bootstrap seems to offer simi ...

Challenges with Hover Dropdowns in Bootstrap Navigation Menu

Check out this screenshot of a navbar PSD design I'm aiming for: To make my navbar dropdown show up upon hovering, I've implemented the following JavaScript: $('.navbar .dropdown').hover(function() { $(this).find('.dropdown-men ...

Ways to maintain uniform size in displaying images even when they are of different dimensions

Within my web application, administrators have the ability to upload various images that will be displayed on the site. The challenge arises from the fact that these images come in different sizes and dimensions. However, it is important that all users w ...

The z-index is preventing me from selecting a certain area

I'm currently facing a challenge with a Bootsrap card that seems to be unclickable and I am unable to type input into the form inside of it. The root cause appears to be related to the z-index that I used to position the card "behind" the header and f ...

Arranging Elements in Reverse Order Using ngx-order-pipe

I have successfully sorted an Array in ascending order, but now I am struggling to figure out how to implement sorting in descending order using ngx-order-pipe. $ npm install ngx-order-pipe --save TS dummyData: any[] = [ { name: 'G' }, ...

Seeking assistance with implementing Styles using the .css() function in Jquery. Any guidance is appreciated

This particular style is exactly what I am looking for. body{ background: url("img/Background_Home.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; ...

How can Angular reactive forms display validation errors within a popup window?

Is it possible to display validation errors in a material dialog when using Angular reactive forms? Is there a way to subscribe to formControl.errors and take action when an error occurs? For example: this.formControl.errors.subscribe(errors => { ...

CSS - stacking containers vertically with scrollbars

I am in need of a vertical stack of blocks, which may include scrolls, contained within a fixed-sized container without scrolls. The number of visible blocks is dynamically managed by JavaScript code. Some blocks can be hidden or shown, and when a block is ...

A guide to building a dynamic form slider that showcases variable output fields with Javascript

I'm interested in creating a Slider Form that shows different output fields when sliding, using Javascript. Something like this: https://i.sstatic.net/3Isl4.png Could anyone provide suggestions on how to achieve this or share any links related to so ...

Using CSS3, HTML5, and Javascript to emulate the visual and interactive design of the WP7 Metro UI

Is it possible to find examples demonstrating the recreation of typical Metro UI controls using CSS, javascript or HTML5 for Windows Phone 7? ...

What is the best way to navigate from an Angular page to a Spring Boot page?

I am currently working on an application that uses Angular 6 for the front end and Spring Boot for the back end. While implementing the user authentication module, I need to redirect users to either the student or staff home page after login. However, I s ...