Ways to apply css to a particular page in HTML?

I am working on creating a webpage using Angular and I have three different stylesheets that are being called in all pages. However, I now need to apply a specific CSS block only to my home page. I attempted to use a less file for this purpose.

HTML:

// The following code is for the home page

<div class="homePage">
<div class="content">

</div>
</div>

//This code is for inner pages

<div class="content">

</div>

CSS:

.homePage
{
    .content
    {
        background-color: #F00;
        color: #FFF;
    }
}
.content
{
    background-color: #000;
    color: #FFF;
}

Unfortunately, the above code is not functioning as expected. Any help would be greatly appreciated.

Answer №1

If you want to create a universal style for the .content division, follow these steps:

.content {
    background-color: #000;
    color: #FFF;
}

To customize or overwrite the style of the .content division for specific pages, wrap it in a parent div like this:

HTML

<div class="special-page">
   <div class="content"></div>
</div>

CSS

.special-page .content {
    background-color: #F00;
}

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 simple method to enable automatic video playback within a lightbox using FancyBox and Video JS?

Check out Fancy Box at Explore Video JS at To see the effect I'm aiming for, visit this link: and click on "Open OverLayed video". I'm interested in achieving this with FancyBox and Video JS for HTML 5 video with a flash fallback. Is there a ...

What is the best way to ensure an element fills the entire height of its container?

Is there a way to handle the overflow of a div when it exceeds its container's size without specifying the height? Requirements: .Wrap must adjust in height and should not have a fixed height. .Head needs to have a fixed height. .Body should become ...

How can you align a div next to another using the float property in CSS?

/*Custom Styling for Divs*/ #box1 { border: 1px solid; border-radius: 25px; width: 900px; } #box2 { border: 1px solid; border-radius: 25px; width: 430px; } #box3 { float: right; border: 1px solid; border-radius: ...

Javascript function encountering difficulty accessing the 'this' variable

I am embarking on a new HTML5 game project, my very first one. Right now, I am working on creating a function that holds variables. While I cannot recall its exact name, I remember the process from a tutorial. In my attempt to set up some of these variable ...

Showing an image stored in an array using JavaScript

This script is designed to pull images from a specific location on an HTML page. images = new Array(); images[0] = new Image(); images[0].src = "images/kate.jpg"; images[1] = new Image(); images[1].src = "images/mila.jpg"; document.write(images[0]); I&a ...

Creating a custom jQuery function that incorporates the `window.onbeforeunload` event handler

I am looking to enhance this code with a "window.onbeforeload" event that displays a message preventing the user from leaving the current page without adding the products to cart. The message should only appear when the quantity is greater than 0 and whil ...

Seeking assistance with printing an HTML template using a printer in Angular 2. Can anyone provide guidance on how

I have a scenario where I need to print an HTML template from within my Angular 2 component. Specifically, I want to be able to click on a print button on the same page and trigger the print function, which would display a print preview and allow the use ...

Optimizing Textpaths Placement within SVG Elements

Check out this sample fiddle. (Make sure to view it in Firefox) Any suggestions on how I can adjust the positioning of my textpath within my SVG so that it isn't hidden? I attempted to include x and y attributes in both the svg and text tags, but the ...

Ways to implement JavaScript and CSS to set a specific zoom level for a webpage

Looking for a solution using html/css/javascript to standardize the zoom level on a website page. Any suggestions on how to implement this with javascript? ...

Separate the paragraph within an HTML string and eliminate any paragraph that is empty

I need help splitting a string of HTML into an array list, with the condition that the paragraphs should not be empty. Each paragraph should contain some normal text, and if it only contains HTML text without any normal text like: <htmltag>&nbsp; ...

How to handle users with disabled Javascript? Considering redirection to alternate sites for users with script disabled?

I've dedicated today to strategizing the best approach for revamping our company's website, taking into consideration that less than 1% of web users have JavaScript disabled. Our management team strongly believes in ensuring that our website rem ...

In Chrome, the latest SVG border-image-source is not functioning properly

For the past 6 months, I successfully used border-image-source to create a custom border on one of my websites. Recently though, I noticed that it no longer appears in Chrome, although it still works in Safari. Here is the code snippet I have been using: ...

Convince me otherwise: Utilizing a Sinatra API paired with a comprehensive JS/HTML frontend

As I embark on the journey of designing a social website that needs to support a large number of users, I have come up with an interesting approach: Implementing Sinatra on the backend with a comprehensive REST API to handle all operations on the website ...

Issue with CSS Scroll Bar

I recently incorporated an Accordion and Slideshow feature into my website located at However, when clicking Play on either feature, a scroll bar unexpectedly appears causing the page to shift. I suspect that I may have forgotten to set the height for a ...

Horizontal navigation bar encroaching on slideshow graphics

I'm encountering difficulties aligning the horizontal menu below the image slider. When I have just an image without the slider, the menu aligns properly (vertically), but as soon as I introduce the code for the slider, the menu moves to the top and d ...

Changing the class of a div in JavaScript from one class to another

On my HTML page, I have a div with a CSS class assigned to it. The goal is to switch the current class for another when a button is clicked. It's crucial that not a single CSS property within the class is altered - the entire class must be replaced en ...

Struggling with implementing the group by feature in AngularJS?

Currently, I am trying to group a select-window by 2 different object arrays - subcategories and rootcategories. Each subcategory has a relation id that links to the rootcategory's id. My goal is to have the dropdown window group the subcategories bas ...

attempting to showcase the initial and subsequent forms during the second phase

Below is a code I've written for a multi-step form, everything is functioning properly here. However, currently when we are at the first step and click on the next button, the next step form will display. I want to modify this so that when the next bu ...

Guide to showing the current time with ng-forms

Implement a time input using ng-forms <input type="time" class="form-control" path="time" formControlName="time" [ngClass]="{'is-invalid': submitted && f.time.errors}" /> ...

Creating an ng-form to dynamically submit a form without requiring a specific ng-model

Revamped the code for a clearer question A big thank you to everyone for all the help I've received so far! I have dynamically generated input boxes with varying numbers of inputs and want to submit them on-the-fly.... How can I pass inputs from ...