简体   繁体   English

HTML中的CSS代码无效

[英]CSS code in HTML no effect

I write the code in Notepad and execute by Chrome, but I don't see the color appaear, 我在记事本中编写了代码,然后由Chrome执行,但是看不到颜色,

http://i.imgur.com/RJHb2Xp.png

it seems that the CSS part of code doesn't take effect, what should I do to let the CSS part take effect? 看来代码的CSS部分没有生效,我应该怎么做才能使CSS部分生效?

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>TITLE</title>
        <style type="text/css">
            body {background:white; color:black}
            a:link {color:red}
            a:visited {color:green }
            a:active {color:blue}
        </style>
    </head>
    <body>
        <h1>B blue T Black</h1>
    </body>
</html> 

<h1> is not an <a href=""> so none of your a: styles will apply, only body { color: black; } <h1>不是<a href="">因此您的a:样式均不适用,仅body { color: black; } body { color: black; } will be applied, that's why your text is black. body { color: black; } ,这就是您的文本为黑色的原因。

Replace your a: rules with a single h1 rule or replace the <h1> with <a href="#"> . 用单个h1规则替换a:规则,或将<h1>替换为<a href="#">

you can try this one: 您可以尝试以下一种方法:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>css</title>
        <style type="text/css">
            body {background-color:white; }

h1 
{
color:red;
}
        </style>
    </head>
    <body >

        <h1>B blue T Black</h1>
    </body>

Your header is not a link. 您的标题不是链接。 Your CSS is set up properly, it's just that there are no links to be styled. 您的CSS设置正确,只是没有要设置样式的链接。 Wrap your tag with an and you should be good to go! 用来包裹标签,您应该一切顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM