Struggling to organize the style sheet separately from the HTML while working on the web page. Challenges with getting it to

After experimenting with some basic HTML and CSS, I noticed an interesting behavior. If I remove the comment tags around the style block, the background turns hot pink. However, when I link to the external style sheet, the expected blue color doesn't appear. Both test.html and test.css are located in the same directory.

The browser reports the following error:

test.html:9 GET file:///test.css net::ERR_FILE_NOT_FOUND - Crome on Mac.

I'm fairly new to all of this, but I believe I have a good grasp of what needs to be done here.

.p {
  background-color: blue;
}
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8>
  <title>Test</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="test.css">
<!-- <style>
    p{background-color: hotpink}
</style> -->

</head>
<body>
  <app-root></app-root>
  <p>This is a test of color</p>
</body>
</html>

Answer №1

If you want to style a ".p" element, make sure you are targeting the correct class name. Simply remove the dot before "p" and your styling issue should be resolved!

Answer №2

To resolve the issue at hand, simply eliminate the base tag from your HTML document. The presence of this tag has caused disruptions by altering the "href" attribute within your link tags to "/", resulting in a reference error and preventing the browser from locating your test.css file.

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

Alignment of Table with Form Section

I need help figuring out how to align a table next to a form section. Here is the layout I am aiming for: #Form Label: |TextBox| Label: |TextBox| Label: |TextBox| Label: |TextBox| ---------------------------------------------- ...

`Ineffectiveness of CSS media query for font-size adjustment in HTML selector`

I recently implemented the 62.5% trick to adjust my font-size for various screen sizes. However, I noticed that on larger screens, the text appears too small. To address this, I tried increasing the font-size to 80% using a min-width media query. Unfortuna ...

Flickering Button Displayed After Fade-In Animation

After scouring the internet for a solution, I still can't seem to figure out why my code isn't working. Whenever an element fades in on Safari, it quickly flickers or flashes white, almost like a rapid refresh is happening. I've tried vario ...

Tips for verifying blank form fields

Is there a way to validate empty form fields before submission and show an alert? This validation is important as some fields are hidden using v-show. Here is an example: <!DOCTYPE html> <header> <script src="https://unpkg.com/vue@n ...

Angular app - static List mysteriously clears out upon refresh

My goal is to create a login page using Angular. I have an Angular component with HTML, CSS, and TypeScript files that manage this functionality. The HTML file contains two fields (Username and Password) and two buttons (Login and Register). When a user en ...

Animating elements with folding effects using CSS transforms

Check out this square: https://jsfiddle.net/34f93mL3/ If you hover over it, you'll see that the top folds down and turns into a pink polka-dotted pattern when it reaches the bottom. However, my goal is to make it look more like an actual folding mot ...

Bootstrap 4 Navigation Bar: Aligning dropdown menu to the right with overflow opening on the right side

Utilizing Bootstrap 4 for a simple navbar, I recently noticed that my right-aligned dropdown opens to the right, causing overflow and displaying the horizontal browser scrollbar. Here is the code for the navbar: <nav class="navbar navbar-expand-lg nav ...

Conditional rendering of Materialize navbar links

I am currently working with React Materialize and React Router Dom. My goal is to display navlinks only to authenticated users using conditional rendering. However, when I implement it as shown below, the navlinks are displayed vertically instead of hori ...

Ways to display or conceal various divs by employing an if/else statement?

I am aiming to conditionally display various divs based on certain criteria: Show the "x" div if it's not already visible Display the "y" div only if the "x" div is already being displayed Show the "z" div only if both the "x" and "y" divs are alrea ...

Is there a way to fix HTML4 4.01 in ASP.NET with Visual Studio 2012?

My ASP.NET empty site in Visual Studio 2012 is designed with HTML4.01 for tables. I have a few <div> elements and keep encountering this warning: </div> <div style="text-align:center;"> <table style="text-align:left; bo ...

The Angular Material Nav Sidebar is specifically designed to appear only when resizing the screen to

I am currently following a tutorial on setting up Angular Material Sidenav with a toolbar from this video (https://www.youtube.com/watch?v=Q6qhzG7mObU). However, I am encountering an issue where the layout only takes effect after resizing the page. I am no ...

Show product name when hovering over the image

Trying to achieve a hover effect where product titles appear in a contained box when hovering over the product image on the bottom overlay, instead of below the image itself. Tried CSS code recommended by Shopify, but it had no effect: <noscript> ...

Disappearance of icon upon hovering in CSS

I am currently working with Angular JS (1.x) and I have a requirement to display tooltip text when hovering over an info icon. The tooltip text appears properly, but the issue is that the icon disappears when hovered over. It reappears once the hover is re ...

Troubleshooting: Issue with Webpack 4 failing to load images in HTML

My webpack configuration seems to be loading images from my SCSS files, but not from the HTML files. Additionally, when I run the BUILD command to deliver my production archives, it doesn't create the "img" folder as expected. As a newcomer to webpack ...

Strange Behavior of Anchor Tags

I've been struggling with my anchor tag not working properly. The desired URL is localhost/VShroff/home/about.php, but it keeps changing to localhost/about.php without redirecting. I've spent a long time trying to figure this out. Here is the HT ...

Moving a popup div along with a marker in Leaflet can be achieved by using the set

After creating a map using leaflet and adding markers to different locations, I implemented code that displays a popup div with a message when a marker is clicked. Here is the code snippet: markers.on("click", function(d) { div.html("This is Some info ...

How can I reference an html <div> element from an <a href> link within the same html document?

I have a piece of text and I want it to trigger an action when clicked. My code looks like this: <h5>Posted On: {{postedDate | date}} <a href="" style="float:right" >Table Plans</a></h5> When the user clicks on Table Plans, it sho ...

Leveraging the powerful Google Maps API to enhance your mapping experience with

After making updates to my code, I managed to keep the Map intact while adding a script to place markers. Unfortunately, the step to add markers is not functioning properly. The data with coordinates is fetched from SQL, converted to JSON using C# and then ...

I'm having trouble getting the footer to stay at the bottom of the window instead of the page. Any tips on

I've exhausted all resources searching for a solution to my issue, but nothing seems to quite fit. The floats on my page are extending beyond the boundaries, and when I load in the footer, it stubbornly sits at the bottom of the initial viewport befor ...

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}" /> ...