简体   繁体   中英

linear-gradient(…) in CSS3 not working according to specifications?

Here's the current version of my webpage:

<html>
<head>
    <title>my site</title>


    <style type="text/css">
        #mtx_bckgd
        {
            font-family: Courier New;
            height: 1000px;
            width: 1000px;
            position: absolute;
            z-index: -1;
        }
        #mtx_bckgd > p
        {
            word-wrap: break-word;
            color: #D8D8D8;     
            overflow: hidden;
        }
        #header
        {
            position: absolute;
            font-family: Trebuchet MS;
            width: 1000px;
            height: 70px;
            text-align: center;
            border: solid 2px #424242;
            top: 25px;
            font-size: 20;
        }
    </style>
    <script type="text/javascript">
        function change_bckgd()
        {
            var bitstr = "";
            for (var i = 0; i < 4000; ++i)
                bitstr += Math.floor(Math.random()*10) % 2 ? "0" : "1";
            document.getElementById("mtx_txt").innerHTML = bitstr;

        }
    </script>


</head>
<body>
    <div id="mtx_bckgd">
        <p id="mtx_txt"></p>
    </div>
    <div id="header">
        <h1>JaminWEB</h1>
    </div>
    <script type="text/javascript">
        setInterval(change_bckgd, 200);
    </script>
</body>
</html>

What I plan on doing is creating a vertical fade across the background, from white at the bottom to light grey (the same grey I used for the 0's and 1's in the background) at the top.

According to W3schools ( http://www.w3schools.com/css/css3_gradients.asp ), the syntax

background: linear-gradient(angle, color-stop1, color-stop2);

means I should add the line

background: linear-gradient(90, white, #D8D8D8)

in the #mtx_bckgd block in the stylesheet. But when I do that, I'm getting a dark blue fade and my 0's and 1's are turning white.

The problem is the "90" in background: linear-gradient(90, white, #D8D8D8) is incorrect. According to W3Schools it should be:

background: linear-gradient(90deg, white, #D8D8D8)

or

background: linear-gradient(to right, white, #D8D8D8);

jsFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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