Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the color fall back to black? [duplicate]

Tags:

html

css

I'm maintaining an old website and had the opportunity to touch old age HTML. So I encountered a strange behavior of the color attribute.

In the following source code, both texts are red:

p {
  color: #ff0000;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>

  <head>
    <title>title</title>
  </head>

  <body>

    <font color="#ff0000">
      hello, world!
    </font>
    <p>
      hello, world!
    </p>

  </body>

</html>

The color code consists of hexadecimal numbers and is (basically) 6 characters. However, the behavior of the color attribute and the color property differ when entering a color code of 6 characters or more.

p {
  color: #ff0000abc;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>

<head>
  <title>title</title>
</head>

<body>

  <font color="#ff0000abc">
    hello, world!
  </font>

  <p>
    hello, world!
  </p>

</body>

</html>

Why is this and how the color attribute works here? I still have to use the color attribute, so I need to know this rule.

Based on this answer, I thought that the color code #ff00c0 was used, but according to inspect actually used color using firefox's dropper tool, actually #ff00ab was using.

like image 965
hyp-ho Avatar asked Feb 29 '20 12:02

hyp-ho


1 Answers

Following the answer you linked we will have the following steps:

#ff0000abc ---> # ff0 000 abc ---> # ff 00 ab ---> #ff00ab

And not #ff00c0

Without considering the # You have 9 characters (divisible by 3) so you won't add any more. You group them into 3 and you cut the extra ones in each group to keep only 2.

like image 125
2 revs Avatar answered Nov 15 '22 08:11

2 revs