0

I am using the following HTML/CSS code on our company's Intranet webpage

<div class="hello">hello</div>

<style>
.hello {
  color: blue
}
</style>

After loading the HTML I get the following result in the inspector:

enter image description here

After inspecting the HTML code I notice that my CSS code suddenly vanishes and I have no idea why. I tried other methods e.g. importing it via stylesheet but every CSS related code vanishes.

Except for inline CSS:

When I use

<h1 style="color: blue;">A heading 
</h1>
<p>A paragraph.</p>

rhe Code works properly.

3 Answers3

2

Put <style> inside <Head>

 <html>
 <head>
    <style>
      h1 {color:red;}
      p {color:blue;}
    </style>
</head>
<body>
    
    <h1>A heading</h1>
    <p>A paragraph.</p>
    
</body>
</html>
Martin
  • 22,212
  • 11
  • 70
  • 132
Dreamer
  • 517
  • 1
  • 4
  • 11
0

enter image description here enter image description here

 <html>
<body>

<h1>A heading</h1>
<p>A paragraph.</p>
<style>
  h1 {color:red;}
  p {color:blue;}
</style>
</body>
</html>

It's visible to me...

Look at following link

Stackoverflow 2 3

  • It does work of course but not for me and I dont know why! When I copy paste your code, save and reopen all that remains is:

    A heading

    A paragraph.

    . When I use '

    A heading

    A paragraph.

    it works'..
    – Valentin Franke Mar 12 '21 at 13:05
  • @ValentinFranke I have edited my question(I added some link look at them...). –  Mar 12 '21 at 16:04
0

<style></style> tag must be included inside the <head></head>. Refer the MDN doc

Naveen Vignesh
  • 1,351
  • 10
  • 21