Dividing a pair of CSS stylesheets on a single HTML page

Currently, I am working on a HTML page that includes multiple javascripts and css files in the header section.

<link href="@Url.Content("~/Content/css/main.css")" rel="stylesheet" type="text/css" />

In order to make the website mobile-friendly, I searched for online resources. However, when I added another css file "app.css," it started causing conflicts with the original main.css file. Since both files are large, I am looking for a way to reference only one of them using a single block of code.

For instance:

I want this section of HTML

<div>
<nav id="topMenu" role="navigation">
        <ul id="nav" class="nav-bar">
            <li><a href="@Url.Action("Index", "Home")">Pending Entries</a></li>
            <li><a href="@Url.Action("MyStores", "Home")">My Stores</a></li>
            <li><a href="@Url.Action("Upload", "Home")">Create New Entry</a></li>
            <li><a href="@Url.Action("MyEntries", "Home")">My Entries</a></li>
            <li><a href="@Url.Action("Index", "ImageGallery")">Gallery</a></li>
            <li><a href="@Url.Action("Logout", "Home")">Logout</a></li>
        </ul>
    </nav>
</div>

to be styled using only this css file

<link href="@Url.Content("~/Content/css/app.css")" rel="stylesheet" type="text/css" />

while ignoring the main.css file, but keeping it applied to the rest of my HTML content.

Answer №1

If you want to ensure that apps.css only applies to your code block, you can assign a specific class to your HTML block, create a "CSS reset" rule for that class, and prefix all rules in apps.css with the same class. Make sure to include both css files, but make sure that apps.css is placed after main.css.

By following this method, you will only need to modify apps.css while keeping main.css intact. It's crucial to have apps.css loaded after main.css so it can override the styles defined in main.css within elements with the .apps class.

In this scenario, you can assign the class "apps" to your div element.

<div class="apps">
<nav id="topMenu" role="navigation">
        <ul id="nav" class="nav-bar">
            <li><a href="@Url.Action("Index", "Home")">Pending Entries</a></li>
            <li><a href="@Url.Action("MyStores", "Home")">My Stores</a></li>
            <li><a href="@Url.Action("Upload", "Home")">Create New Entry</a></li>
            <li><a href="@Url.Action("MyEntries", "Home")">My Entries</a></li>
            <li><a href="@Url.Action("Index", "ImageGallery")">Gallery</a></li>
            <li><a href="@Url.Action("Logout", "Home")">Logout</a></li>
        </ul>
    </nav>
</div>

In apps.css, remember to prefix every rule with ".apps ". Additionally, add a "CSS Reset" style rule at the beginning of apps.css to nullify any effects from main.css.

.apps *
{
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

.apps table {
    border-collapse: collapse;
    border-spacing: 0;
}

Answer №2

Instead of relying solely on media queries, it may be more beneficial to revisit the basics of CSS and address any underlying issues there. The size of both files being large is a concerning issue as well. Rather than loading the entire file for just list styling, consider only including the necessary code.

To ensure that only #topMenu utilizes apps.css, you could prefix each statement in that file with #topMenu.

Answer №3

Like I mentioned before, Isherwood, it's impossible to conceal a CSS. However, you can customize a specific section of the document by applying that CSS when necessary.

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

What causes z-index to be ineffective with sticky elements?

In my website, I've implemented rollover effects in a sticky footer and a responsive menu that stays at the top. However, when the menu is opened and extends over the footer, it covers everything except the rollovers. Closed navigation http://www.mus ...

Create individual account pages with specific URLs in Next.js

I'm currently working on developing a website that will feature individual user pages showcasing their posts and additional information. I'm facing some difficulty in figuring out how to generate new links to access these user accounts. For insta ...

What is the best way to increase the top padding of an anchor link?

I need to create a padding-top effect for my div when the link to the anchor is clicked: <a href="#myAnchor">Proceed to my anchor</a> ... <div id="myAnchor"> ... </div> The challenge lies in wanting to add the padding only when ...

Generate options for a dropdown menu based on the choice made in another dropdown menu utilizing ajax technology

Greetings, I am currently working on a JSP page that features a form with two drop-down lists. The first drop-down is designed to display the country names. While the second drop-down should show the states corresponding to the selected country. I have ...

Problem occurring with Bulma CDN version 0.8.0 failing to identify the spacing helper

Recently revisited an older project I had started some time ago using the Bulma framework. However, for some reason, the 0.8.0 CDN is not being imported or recognized correctly by the spacing classes. Here's the code snippet I had initially: <link ...

tips for correctly importing source files into jasmine-node testing framework

Currently, I am utilizing the jasmine spec library in combination with the jasmine-node runner for node.js. My main query revolves around the correct method to execute tests using a command in the CLI that encompasses both source files and spec files. Wit ...

Local variable reference getting lost in a loop during a jQuery Ajax call

Currently, I am facing an issue with my jQuery ajax calls within a loop. The problem arises when each ajax call returns and I need to retrieve a specific value associated with the original call. However, due to further iterations in the loop, the value of ...

The web page's content remains hidden until it is scrolled into view, despite the fact that the page has finished loading

I'm a beginner with Angular and currently working on creating a website. On the following page , when viewed on mobile, I am experiencing an issue where the content doesn't load until it's brought into view by scrolling down the page. I am u ...

Tips for incorporating background color with CSS pseudo-elements

I'm attempting to replicate the outcome shown in the screenshot but I'm having difficulty achieving it without adding any new DOM elements. When I click on the demo link and choose a date range, the start date and end date selections are not dis ...

Can anyone point out where the mistake lies in my if statement code?

I've encountered an issue where I send a request to a page and upon receiving the response, which is a string, something goes wrong. Here is the code for the request : jQuery.ajax({ url:'../admin/parsers/check_address.php', meth ...

Adjusting font size in dynamic containers relatively

Imagine we have a slider named .outer, which adjusts its height based on the width of the viewport. Inside this slider, there is an example slide called .inner that contains some text. However, when we shrink the window width, the content in slide .inner s ...

PHP page Not Refreshing Properly Without Ajax

I am in need of assistance. Could someone please provide me with a code that has been thoroughly reviewed and tested for errors to address my issue? The program, 22.php, consists of a form. The desired functionality is for the user to enter information and ...

Transmitting Several Pictures at Once Through WhatsApp-WebJS

I have encountered a challenge while attempting to send multiple images in a single WhatsApp message using the WhatsApp-WebJS library. Despite receiving a "success" confirmation without any errors, the images and message fail to appear on WhatsAp ...

I'm curious about the purpose of the "^=" operator in this algorithm for finding the unpaired numbers. What exactly does it do?

I came across a fascinating code snippet that helps find a unique number in a list of duplicate numbers (where each number appears twice, except for one). function findNonPaired(listOfNumbers) { let nonPairedNumber = 0 listOfNumbers.forEach((n) => ...

Guide on iterating through an array of objects a specified number of times to ensure it loops through all child arrays within the objects, if they exist

How can I iterate through an array of objects a certain number of times to access all the child arrays within each object and retrieve their IDs in order? let data = [{ "id": "1", "child": [ { "id": "12", "child": [ { ...

What is the most effective method for integrating additional CSS/JS libraries into a GitHub repository?

I would like to integrate FontAwesome, Bulma, jquery, and jquery-ui into one of my Github repositories for the front-end section. Currently, I am including the JS files or CSS files from these projects in my own JS/CSS folders, but I believe there might ...

Click to Rotate the Shape

I am attempting to apply a rotation effect on a shape when clicked using jQuery and CSS. My goal is to select the element with the id of x and toggle the class rotate on and off. The rotate class utilizes the CSS transform property to achieve the desired r ...

Exploring the Structure of Trees using JavaScript

Here are my terms: var terms = [ { id: 1, name: "Name 1", parent: null }, { id: 2, name: "Name 2", parent: 6 }, { id: 3, name: "Name 3", parent: null }, { id: 4, name: "Name 4", parent: 2}, { id: 5, name: "Name 5", ...

Error: Attempting to retrieve a refresh token from the Google API resulted in an Uncaught ReferenceError, as the

I am currently working on obtaining a refresh token once a user authorizes with Google in order to prevent the need for re-authorization. After studying Google's documentation, I learned that setting the access type to offline is necessary. Now, I am ...

Utilizing Audio Record Feature with a pair of buttons - one for initiating recording and the other for concluding recording

I'm new to Vue.js and trying to create a simple audio recorder that starts recording on click of a button and stops when another button is clicked. The goal is to display the audio file in the template and save it locally as a blob. Here is the templ ...