1

Currently studying computer science, but I've really only dealt with c++ & java. Currently trying to learn html & css, which is obviously not as difficult as having to write the code for a binary search tree which will balance itself after inserting data.

ANYWAYS!! I'm stuck! I dont understand why the .h css style in the following code isn't working on the contents of the div box!! Any help would be great.

<html>

<head>
<title>test</title>
<meta charset="UTF-8">
<style type=“text/css”>
.h {
    color: red;
    text-align: center;  
    }
</style>
</head>

<body>
<div class=“h”>Hello World</div>
</body>

</html>

This is obviously a very simple code of block, but the Hello World doesn't turn red. Would love to know what I am doing wrong.

THANK YOU!

P.S. I have tried checking the output on http://www.littlewebhut.com/html/ and nothing :(

2
  • 5
    The quote marks in your style and div tags are "smart-quotes" that don't match, not real quotes, blame your editor. Commented Jan 11, 2018 at 0:37
  • Thank you so much!! Another user pointed out the same! The smallest of issues always end up being the most difficult to figure out haha Commented Jan 11, 2018 at 0:43

2 Answers 2

3

You are using the wrong set of quotes for the class value.

“h” is different from "h"

This likely happened because of your text editor converting the plain quotes like " to the more fancy ones “ and ”

So to fix it, use:

<div class="h">Hello World</div>

The same goes for type=“text/css” but you don't need to specify this at all; only having <style> will suffice since CSS is the standard for stylesheets.

Make sure to disable smart quotes from your text editor!

Sign up to request clarification or add additional context in comments.

1 Comment

YOU ARE AMAZING!! That is exactly what was wrong! Thank you so much. I had been looking over this trying to understand why it wasn't working. Great eye! :) It truly always ends up being the simplest of issues.
-1

CSS, while simple in appearance, can challenge one's mind. I see that your issue boiled down to unicode or smart quotes. Just an FYI, quotes are actually not necessary on classes applied to HTML elements.

.h {
    color: red;
    text-align: center;  
}
<html>

<head>
<title>test</title>
<meta charset="UTF-8">
</head>

<body>
<div class=h>Hello World</div>
</body>

</html>

2 Comments

This answer is using smart quotes “h” for the class value. Plain quotes should be used "h".
This actually helped tremendously as well!! Thank you! I will rid my html div classes of quotes altogether to simplify!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.