Differences in the way CSS handles 'root' within an external .css file

As I delve into the world of CSS, I've encountered a puzzling issue that has me scratching my head. My objective is to change the background color of the viewport to red.

When I tried using the following code in an external .css file and linked it to my HTML file in the 'head' section, the background color remained obstinately white, completely ignoring my instructions:

 ==== my-external-css-file.css ===
 root 
{ 
   display: block;
   background-color:RGB(255,0,0);     
}


==== my index.html file ====
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>theRed</title>
    <meta name="viewport" content="user-scalable=no, width=device-width"/>

   <link rel="stylesheet" href="my-external-css-file.css"
</head>

The book I'm using as a learning resource advocates for the external CSS file method, but clearly, it's not working for me. So, I decided to bypass this approach and instead include the style directly within the "head" section of my index.html file. Lo and behold, when I placed the desired color change right inside the index.html file itself, the entire viewport background turned a vibrant shade of red:

     ==== my index.html file ====
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>theRed</title>
    <meta name="viewport" content="user-scalable=no, width=device-width"/>

    <style type="text/css"> 
        :root
        {
            background-color:RGB(255,0,0);
        }
    </style>
</head>

Given that both methods entail setting the root's "background-color" property to red within the appropriate "head" section of the html file, what could be causing the failure of the external .css file? Could there be some intricate detail that eludes my understanding as a CSS novice? I use Netbeans as my development IDE, and interestingly, whenever I create a new .CSS file, Netbeans automatically inserts the "display: block" statement. While I have retained this without modification, it appears my efforts are not bearing fruit.

Answer №1

The primary element in HTML is the <main> tag, so you should use the selector main instead of primary.

You seem to have overlooked the inclusion of the : symbol when referencing the :primary pseudo-class in your external CSS. Since HTML always uses main, there is no need to utilize :primary based on current knowledge.

Answer №2

Forget about using root, it's better to stick with elements such as html or body when choosing a color scheme. In your specific case, I recommend setting the body element to:

body {
    background-color: RGB(255, 0, 0);
}

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

Issues accessing my Facebook account due to domain problems

I have developed an HTML5 game that I am currently running in my web browser. My objective is to integrate Facebook login functionality, so I followed a tutorial and replaced the necessary information with my App ID. However, upon running it, an error mes ...

Using Selenium to Implement Accept Policy Targeting

I am attempting to locate and click on a button from dekudeals using selenium. Specifically, I am trying to target the accept button within the site's policy window. The button that needs to be clicked can be found here. I have made several attempt ...

What is the best way to eliminate the gap between the dropdown-toggle button and dropdown-menu items?

Why does a space appear between the dropdown-toggle button and dropdown-menu? Is there a way to remove this space? The box-shadow currently conceals the gap, but it becomes visible once the box-shadow is eliminated. Here is the code snippet: <!DOCT ...

Tips for stacking columns with Twitter Bootstrap?

Looking to design a layout with 3 columns: Column 1 (span 3) - Column 2 (span 8) - Column 3 (span 3) I want Column 2 to partly overlap with Column 1 and Column 3 on each side, all within the same row. What would be the most effective method to achieve th ...

Please input two words in the textbox using AngularJS

I am currently facing a challenge that requires me to make the user input both their first and last name into a single text box. I am using AngularJS for this task, and my goal is to validate the text field using ng-pattern. The requirement is that the fie ...

Having difficulty modifying the styling of a paragraph within a div container

I have been working on a function that is supposed to adjust the font-size and text-align properties of a paragraph located within a div tag once a button is pressed. function customizeText() { document.getElementById('centretext').innerHTML = ...

Utilizing erb within a coffeescript file for modifying the background styling

Is there a way to change the background image of a div based on user selection from a dropdown menu? For instance, if the user picks "white" the background image becomes white, and for "red" it changes to red. I'm struggling with this in coffeescript ...

Ensuring a consistently positioned footer at the bottom

I understand that this might not seem like a significant issue, but I'm encountering some difficulties. In my main.html file, there are three divs. The first div contains the navigation bar, the second div is an "empty" div that uses JQuery/Javascript ...

Is it possible for flex-grow to affect images? What steps can I take to identify any issues within my code?

<section> <div class="section-header"> <h5>Discover Our Team</h5> <h1>Meet the Experts</h1> <h5>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt, eaque.</h5> ...

Guide to creating animated sections using only CSS as you scroll the webpage

I am searching for a method to add animation effects (using @keyframes, transform...) to certain elements as the user scrolls down the page. For instance: When the offset is 0: the div will have a height of 100px. When the offset is between 0 and 100: th ...

Challenges related to a hamburger icon menu

Trying to create a functional hamburger menu but facing some difficulty in getting it right. Here's the concept: The page layout on larger screens should resemble this: https://i.sstatic.net/CBqMP.png Smaller screens will display a hamburger menu, ...

What might be causing my grid columns to move onto a new line?

I am facing an issue with my Bootstrap 4 buttons. I have set them up to be 4 columns each within a grid, expecting them to all remain on the same row. However, the third button is dropping down to the next line and I can't seem to figure out why. Her ...

Can you explain the difference between the <li> and <div> elements in HTML? How are they used differently

I'm currently exploring the elements for Selenium usage. I have a question about the <li> tag in HTML - could you explain its significance to me? Also, how does it differ from the <div> tag? ...

Would it be advisable to store HTML data in a database?

Currently, I am in the process of developing a blog-app project using Angular 7. For the backend, I am utilizing firebase cloud functions and performing CRUD operations by storing HTML content in firebase with the help of Angular - CKEditor component. Whe ...

Prevent scrollbar from appearing while splash page loads

Looking for help with a script to create a splash/intro page loader. $(function(){ setTimeout(function() { $('#splash').fadeOut(500); }, 6000); }); The current script hides the intro page after 6 seconds, ...

Developing a Highchart Graph using JavaScript

I am trying to develop a high chart graph. Check out my code on FIDDLE LINK. I have two values, a and b, for the x-axis and y-axis. The issue arises when the difference between a and b is minimal, such as when both are equal (-9). In such cases, the grap ...

Using two body tags in the code of a Wordpress site can lead to malfunctioning

I've encountered a strange issue with my Wordpress sites hosted on BlueHost. There seems to be a double <head> tag appearing in the HTML code, even though there is only one. This duplicate tag is causing issues with the proper rendering of the s ...

AngularJS selectChosen does not have built-in support for translation

<select chosen options="myOptions" ng-model="StatCode" data-placeholder="{{'PleaseSelect' | translate}}" ng-options="item[0] as item[1] + ' / ' + item[0] for item in myOptions" required>< ...

Deactivate click events in the container div

Here is the html code snippet that I am working with: <div class="parent" ng-click="ParentClick()"> . . . <div class="child" ng-click="ChildClick()"> Some Text </div> </div> When clicking on Som ...

What steps can I take to stop a select box within a flex container from shrinking?

Currently working on some code that involves a flex container. Struggling to prevent fields from shrinking too much on smaller screen sizes. var crsdesc; //var for new window function popup(mylink) { if (!window.focus) return true; var href; if (t ...