The HTML page seems to have a glitch where it does not recognize the ID's specified in the

Feeling like an HTML and CSS newbie as I encounter my first roadblock.

In my attempt to code, I have both my CSS and HTML files saved in the same directory using Notepad++. However, every time I try to open the HTML file in a browser, the specified ID in the CSS is not functioning properly - particularly centering and changing color.

This seems like one of those quick fixes waiting to be discovered.

Main.css

   <style>
   #change{color:red; text-align:center }
   </style>

example.html

<html>
<html lang="en">
<head>
<meta charset="utf-8">
<Title>sample</title>
<link rel="stylesheet"  href="folder/main.css" />
</head>

 <body>
 <p id="change">Sample sample sample </p>     //HERE IS WHERE THE ID IS
 </body>

  </html>   

Any thoughts on what might be causing this issue?

Answer №1

To merge the existing answers into one cohesive response:

If your website's directory structure consists of only the index.html and main.css files in the same folder, then the correct path to link them is as follows:

<link rel="stylesheet" type="text/css" href"main.css"/>

The use of style tags within your current css file is redundant and unnecessary. While style tags can be utilized in HTML, they are typically not necessary.

Lastly, ensure that the HTML code provided does not act as a comment. If there are any comments indicated by (/*), be sure to remove them from your current code.

Answer №2

It is recommended to eliminate the <style> and </style> tags from your HTML. Keep your main.css file dedicated strictly to CSS styling:

#change{ color:blue; font-size:18px }

Answer №3

  1. verify the CSS path.

Do your paths look like this?

- example.html
- folder/
 |-   main.css
  1. Remove <tag> in main.css

In CSS files, there should not be any HTML tags present.

Answer №4

Welcome to the exciting world of web design! Despite its challenges, your determination to solve problems will ensure a smooth journey. It's commendable that you attempted to troubleshoot before seeking help. Let's break it down step by step:

  1. Remember, main.css does not require <style> tags. Those are only necessary when editing CSS internally within the <head> element of an HTML page. In *.css files, simply start defining CSS rules.

  2. Always maintain proper spacing like this:

    #change { color: red; text-align: center; }
    (Don't forget to end each CSS rule with a semi-colon).

You can also format it as follows:

#change { 
    color: red;
    text-align: center; 
}

  1. The characters /* and */ denote CSS comments. Anything between these characters will be ignored by the browser.

  2. The line

    <link rel="stylesheet"  href="folder/main.css" />
    could be causing issues if both your HTML and CSS files are in the same folder. If so, just use href="main.css" /> Also consider adding
    <link rel="stylesheet" type="text/css" href="main.css" />
    to specify the file type to the browser.

For a visual example, see below:

#change {
  color: red;
  text-align: center;
  }
<html lang="en">

<head>
    <meta charset="utf-8">
    <Title>sample</title>
    <link rel="stylesheet" href="folder/main.css" />
</head>

<body>
    <p id="change">Sample sample sample </p>
</body>

</html>

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

Chrome is experiencing a delay in closing the Select Option dropdown menu

On my webpage, I have two select option buttons placed on different tabs. Whenever one button is changed, I want to update the value of the other button and assign it to a specific element like a span in the example code provided. While everything works sm ...

The action of setting the inner HTML of "main" to "testing" is temporary and will revert back to its original state rather than permanently change

In this snippet of my Java.html code, I am inserting the <a href='' onclick='load_des()'><li><p>$row[Title]</p></li></a> element into the div element with the ID "main". This content is being echoed f ...

Ways to expand the height of a child element within a flex container that has been

I am facing an issue with stretching the children of a column flexbox container. While I can stretch one of the flexbox child elements, I am unable to stretch its nested children. Below is an example where .flex-child-2-child and .flex-child-2-child-child ...

Adjust the size of an element by utilizing a different element

I'm facing a challenge with this code. I need to dynamically set the width of the "wrap-description" divs to be equal to the width of the corresponding "picture-damage" images plus an additional 20 pixels. Since there will be multiple elements for bot ...

How can I customize the appearance of the arrow in a Material UI tooltip?

Looking to enhance the appearance of a Material UI tooltip arrow with custom styling, but struggling to set the border and background colors. Here's the current configuration in React: const useStylesBootstrap = makeStyles(theme => ({ arrow: { ...

Issues with CSS and Node Express

I'm currently experimenting with some code and running into a problem. Using Express, I noticed that only the CSS selector for the body element is working. However, if I remove the body tag, then the next container works, but the ones after that do n ...

Tips for initiating a function at a designated scroll point on a webpage

Currently, I am testing out a code snippet that allows images to flip through in a canvas element. I'm curious if it's possible to delay the image flipping effect until the viewer scrolls down to a specific section of the page where the canvas i ...

Is it feasible to use HTML to improve IE's tolerance for errors in markup, such as unnecessary tags?

I created a jQuery tabs element in the following way: <div id="tabs"> <ul> <li><a href="#tabs-1">Nunc tincidunt</a></li> <li><a href="#tabs-2">Proin dolor</a></li> < ...

Issue with php's mysql_fetch_assoc() function

Seeking to fetch data from a function that holds my query. The retrieved data is sent back to the main page for printing using a while loop but encountering an error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given ...

Is it possible to have a div automatically scroll when hovered over, while also hiding the scroll bar specifically for that div?

Is there a way to autoscroll a specific element onmouseover or via an image map while also hiding the scrollbars for that div? I seem to be struggling with this task despite weeks of learning javascript and not being able to find the right solution online. ...

When utilizing jQuery version 1.10.2, the HTML markup shows up prior to the page completing its loading process

I am trying to import one HTML page into another, but when I load or refresh the page, the HTML markup appears before the page fully loads. How can I fix this issue? <head> <script type="text/javascript" src="js/jquery-1.10.2.js" ></scr ...

JavaScript code for Tree not functioning correctly on Internet Explorer

Seeking assistance to fix a bug in my JavaScript program. The code works perfectly on Google Chrome and Firefox, however it encounters an error in Internet Explorer 8 as indicated below. Any suggestions on how to resolve this issue would be greatly appreci ...

toggle the outer div along with its corresponding inner div simultaneously

On one of my pages (let's call it "page1"), I have multiple divs, some nested within others. These divs are initially hidden and toggle on when a specific link is clicked (and off when clicked again). To view a nested div, the outer div must be opened ...

How come my columns are stacking on top of each other instead of being positioned side by side?

I am having an issue with my products displaying below each other instead of next to each other in their own column. How can I adjust the layout so that they appear side by side? View image <tr> <th>Month</th> <div *ngFor="let p ...

In what way can the button display the permission directly on the page?

When the website notification is granted, a green button should be displayed. If it is denied, show a red button instead. The button comes with a CSS style and a checkbox but does not have the permission to grant or allow any permissions on the page. Butt ...

Elements vanish when SHAKE effect is in use

I've been experimenting with this framework and I'm struggling to get the shaking effect to work properly. Whenever I hover over an element, other divs seem to disappear. I tried using different versions of JQuery and JQuery UI on JSFiddle, and i ...

How to Implement a Dropdown Menu in HTML and CSS for Navigation Bars

Currently, I am in the process of creating a website at www.bossfakeid.co.uk. I am looking to add a dropdown menu to the "Products" section of the navbar. I found a dropdown menu solution that I would like to implement from this link: http://codepen.io/wil ...

Animating the appearance and behavior of radio buttons using CSS transitions and JavaScript

My jQuery code allows me to fetch attributes from the .item element, but I'm having trouble with my CSS transitions not working as intended. To see the desired transition effect, try replacing .item with .item-tile. How can I make my CSS transitions ...

Seamless animation with Angular 4

I'm working on creating a dynamic Homepage in Angular 4 with various cards such as stats, charts, etc., all enhanced with animations. One interesting feature I've implemented is the ability to toggle chart cards to expand to full screen by clicki ...

What is the process for implementing transitions using SASS?

When the pointer hovers over it, the transition effect kicks in smoothly. However, it reverts back to its original size abruptly when the mouse pointer is no longer hovering over it. What I aim for is for the cardLink to scale smoothly ...