CSS按钮动画不起作用。

4
我在我的页面上设置了一个来自这个教程的动画CSS按钮。虽然该按钮出现在我的页面上,但却没有动画效果。不过,在<div id="wrapper">之外时,悬停动画确实有效,但是这样我就无法将其放置在想要的位置上。我已经在我的index.html和style.css中包含了与按钮相关的代码,并在我的index.html中突出显示了该按钮的<div>。如果您需要wrapper或main的CSS,请告诉我,我会尝试找出它们。
您可以在http://suchryan.com/gtd/#download上看到我的问题的实时版本,以及我想要实现的目标在http://suchryan.com/working/上。
请告诉我我缺少什么,我已经卡在这里几个小时了 :(
index.html
    <!-- Wrapper-->
    <div id="wrapper">

        <!-- Nav -->
        <nav id="nav">
                <a href="#me" class="fa fa-info-circle active"><span>File Information</span></a>
                <a href="#download" class="fa fa-download"><span>Download File</span></a>
                <a href="http://suchryan.com/#work" class="fa fa-arrow-left"><span>Back to Portfolio</span></a>
        </nav>

        <!-- Main -->
        <div id="main">

                <!-- Me -->
                <article id="me" class="panel">
                    <header>
                        <h1>Grab the Diamonds</h1>
                        <span class="byline">A simple <a href="http://minecraft.net">Minecraft</a> inspired 2D platform game.</span>
                    </header>
                        <a href="#download" class="jumplink pic">
                            <span class="jumplink arrow fa fa-chevron-right"><span>Go To Download</span></span>
                            <img src="images/me.jpg" alt="" />
                        </a>
                </article>

        <!-- Download --> 
        <article id="download" class="panel">
            <header>
                <h2>Download the Installer</h2>
            </header>
                <p>
                Grab the Diamonds is a simple 2D platformer that I created in my first year of college. It was written in GLBasic 
                and is loosely based on the game Minecraft. It is currently unfinished, although I may choose to continue with 
                it someday. The game is fully functional, yet only the first level is able to be completed as the others are 
                unfinished. None of the images are compressed, so the file size is quite large (36Mb). A
                VirusTotal Scan can be <a href="http://goo.gl/iaTdiY">found here</a> for anybody that is a little skeptical.
                </p>
                =============== FROM HERE ===============
                <div class="downbutton" align="center">
                    <a href="files/GtD_Installer.exe">Download Me</a>
                    <p class="top">.exe Application</p>
                    <p class="bottom">36 MB</p>
                </div>
                =============== TO HERE ===============
        </article>
    </div>

style.css

.downbutton
{
    width: 200px;
    margin: auto;
}

.downbutton a
{
    display: block;
    height: 50px;
    width: 200px;

    /*TYPE*/
    color: white;
    font: 17px/50px Helvetica, Verdana, sans-serif;
    text-decoration: none;
    text-align: center;
    text-transform: uppercase;

    /*GRADIENT*/  
    background: #00b7ea; /* Old browsers */
    background: -moz-linear-gradient(top, #00b7ea 0%, #009ec3 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#00b7ea), color-stop(100%,#009ec3)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #00b7ea 0%,#009ec3 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #00b7ea 0%,#009ec3 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #00b7ea 0%,#009ec3 100%); /* IE10+ */
    background: linear-gradient(top, #00b7ea 0%,#009ec3 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00b7ea', endColorstr='#009ec3',GradientType=0 ); /* IE6-9 */
}

.downbutton a, .downbutton p
{
    -webkit-border-radius: 10px;
       -moz-border-radius: 10px;
            border-radius: 10px;

    -webkit-box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
       -moz-box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
            box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
}

.downbutton p
{
    background: #222;
    display: block;
    height: 40px;
    width: 180px; 
    margin: -50px 0 0 10px;

    /*TYPE*/
    text-align: center;
    font: 12px/45px Helvetica, Verdana, sans-serif;
    color: #fff;

    /*POSITION*/
    position: absolute;
    z-index: -1;

    /*TRANSITION*/  
    -webkit-transition: margin 0.5s ease;
       -moz-transition: margin 0.5s ease;
         -o-transition: margin 0.5s ease;
        -ms-transition: margin 0.5s ease;
            transition: margin 0.5s ease;
}

/*HOVER*/
.downbutton:hover .bottom
{
    margin: -10px 0 0 10px;
}

.downbutton:hover .top
{
    margin: -80px 0 0 10px;
    line-height: 35px;
}

/*ACTIVE*/
.downbutton a:active
{
    background: #00b7ea; /* Old browsers */
    background: -moz-linear-gradient(top,  #00b7ea 36%, #009ec3 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(36%,#00b7ea), color-stop(100%,#009ec3)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #00b7ea 36%,#009ec3 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #00b7ea 36%,#009ec3 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #00b7ea 36%,#009ec3 100%); /* IE10+ */
    background: linear-gradient(top,  #00b7ea 36%,#009ec3 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00b7ea', endColorstr='#009ec3',GradientType=0 ); /* IE6-9 */
}

.downbutton:active .bottom
{
    margin: -20px 0 0 10px;
}

.downbutton:active .top
{
    margin: -70px 0 0 10px;
}
2个回答

2
这不是JS问题,而是CSS问题:
/* First add the following rules to your .downbutton a style rules */
position: relative; /* so z-index is working */
z-index: 2; /* increase it to 'hide' the additional infos */

/* Second change .downbutton p z-index (currently -1) */
 z-index: 1; /* to set them 'behind' the button but in front of bg */

现在您已经可以看到p元素,并且hover将再次“工作”(它一直在工作),但是p标签只是不可见。仍然存在标签位置错误的问题(左对齐在容器中,而不是居中)。您可以通过将.downbutton内的两个p标签居中(left: 50%; margin-left: -p标签宽度的一半)或通过使完整的.downbutton容器本身居中来修复该问题。

你是一个美丽的人类。这个工作完美地运行了。非常感谢你 :) - JustRyan

-1

看起来正常 这里

Just copied your code to Jsfiddle, and voila its working.

这似乎是你错误的页面中缺少的内容(尽管我仍在努力解决这个问题...)。

.downbutton
{
    width: 200px;
    margin: auto;
}

嗯,这没有其他<div>或<article>的CSS,这就是为什么它在http://suchryan.com/working上有效的原因。这意味着故障肯定出现在那些标签中的某个地方。我会再试试看。 - JustRyan
我没有给你投反对票 :/ 我甚至还不能对答案进行投票,因为我没有达到所需的声望值。 - JustRyan
好的,那么也许是一些继承的CSS正在覆盖它。不过我需要看到实际的问题(对于大写字母表示抱歉,似乎论坛充满了恶意评论和新手)。 - Mohd Abdul Mujib
没问题。我有两个不同的CSS文件:style.css和desktop-style.css。我已经将它们与我的index.html一起上传到Jsfiddle,并将desktop-style.css粘贴到JavaScript部分中。链接在这里:http://jsfiddle.net/vsb6G/,如果你想看一下。如果不想,没问题。我相信我最终会解决的:p。 - JustRyan
感谢您的帮助,但现在没有必要了,因为axel.michel的解决方案有效了。无论如何还是非常感谢您的帮助 :) - JustRyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接