CSS3 Gradient不能作为背景

时间:2015-07-18 23:06:40

标签: html css html5 css3

我遇到了问题,我无法将渐变设置为我的网站背景(渐变来自http://www.colorzilla.com/gradient-editor/),而在浏览器中运行时,背景只是白色。即使我只是设置背景:#171717;有黑色背景,但是当我添加渐变代码时它只是白色。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>XXXXXXXXXXXXXX</title>
    <style type="text/css">
    asdasd  
     body {
            background: #171717;   
            /* IE9 SVG, needs conditional override of 'filter' to 'none' */
            background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjMTMzNzYxIiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L3JhZGlhbEdyYWRpZW50PgogIDxyZWN0IHg9Ii01MCIgeT0iLTUwIiB3aWR0aD0iMTAxIiBoZWlnaHQ9IjEwMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
            background: -moz-radial-gradient(center, ellipse cover,  #000000 0%, #133761 100%); /* FF3.6+ */
            background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,#000000), color-stop(100%,#133761)); /* Chrome,Safari4+ */
            background: -webkit-radial-gradient(center, ellipse cover,  #000000 0%,#133761 100%); /* Chrome10+,Safari5.1+ */
            background: -o-radial-gradient(center, ellipse cover,  #000000 0%,#133761 100%); /* Opera 12+ */
            background: -ms-radial-gradient(center, ellipse cover,  #000000 0%,#133761 100%); /* IE10+ */
            background: radial-gradient(ellipse at center,  #000000 0%,#133761 100%); /* W3C */
            filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#133761',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */

            margin: 0;
            font-family: 'Arial';
        }
        #menu{
            font-size: 24px;
            color: #BEABD6;
            height: 28px;
        }
        a{
            padding: 12px 24px;
            text-decoration: none;
            text-align: center;
        }
        div {
            width: 598px;
            height: 100px;


            position: absolute;
            top:0;
            bottom: 0;
            left: 0;
            right: 0;

            margin: auto;
        }
    </style>
</head>
<body>
    <div id="menu">
        <a href="#">XXXXXXX</a>
        <a href="#">XXXXXXX</a>
        <a href="#">XXXXXXXXX</a>
    </div>
</body>
</html>

2 个答案:

答案 0 :(得分:3)

解决方案非常简单:移除asdasd前面的body {

旁注:Paulie_D提供的解决方案不是解决问题所必需的。

答案 1 :(得分:1)

代码工作正常....除了你必须从body

中删除零边距

body {
         background: #171717;
         /* IE9 SVG, needs conditional override of 'filter' to 'none' */
         background: url(data:image/svg+xml;
 base64, PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjMTMzNzYxIiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L3JhZGlhbEdyYWRpZW50PgogIDxyZWN0IHg9Ii01MCIgeT0iLTUwIiB3aWR0aD0iMTAxIiBoZWlnaHQ9IjEwMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
         background: -moz-radial-gradient(center, ellipse cover, #000000 0%, #133761 100%);
         /* FF3.6+ */
         background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, #000000), color-stop(100%, #133761));
         /* Chrome,Safari4+ */
         background: -webkit-radial-gradient(center, ellipse cover, #000000 0%, #133761 100%);
         /* Chrome10+,Safari5.1+ */
         background: -o-radial-gradient(center, ellipse cover, #000000 0%, #133761 100%);
         /* Opera 12+ */
         background: -ms-radial-gradient(center, ellipse cover, #000000 0%, #133761 100%);
         /* IE10+ */
         background: radial-gradient(ellipse at center, #000000 0%, #133761 100%);
         /* W3C */
         filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#133761', GradientType=1);
         /* IE6-8 fallback on horizontal gradient */
         background: radial-gradient(ellipse at center, #000000 0%, #133761 100%);
       }
       #menu {
         font-size: 24px;
         color: #BEABD6;
         height: 28px;
       }
       a {
         padding: 12px 24px;
         text-decoration: none;
         text-align: center;
       }
       div {
         width: 598px;
         height: 100px;
         position: absolute;
         top: 0;
         bottom: 0;
         left: 0;
         right: 0;
         margin: auto;
       }
<div id="menu"> 
  <a href="#">XXXXXXX</a>
  <a href="#">XXXXXXX</a>
  <a href="#">XXXXXXXXX</a>
</div>