2017-07-25 108 views
1

这可能有一个明显的答案,但我只是没有看到它。我更新了这个代码来纠正具有article section h1错误top值。我还添加了:hover触发article section h1。否则,这是我从webdesigner杂志拿到的相同代码来演示动画标题效果,但FF或Chrome中都没有发生。我为转换样式添加了-webkit和-moz-前缀,但仍然没有。请告诉我我做错了什么。即使使用-webkit-和-moz-前缀,教程的css过渡也不起作用

body,html { 
 
\t display:block; 
 
\t width: 100%; 
 
\t height: 100%; 
 
\t background: white; 
 
\t color:black; 
 
\t padding: 0; 
 
\t margin: 0; 
 
\t font-family: Helvetica, sans-serif; 
 
} 
 
nav { 
 
\t position:fixed; 
 
\t top: 0; 
 
\t width: 100%; 
 
\t z-index: 9999; 
 
\t background: white; 
 
} 
 
article { 
 
\t position: relative; 
 
\t padding-top: 5em; 
 
} 
 
article section { 
 
\t position: absolute; 
 
\t opacity: 0; 
 
\t width: 100%; 
 
} 
 
article section:target { 
 
\t left: 0; 
 
\t opacity: 1; 
 
\t z-index: 9999; 
 
} 
 
article section h1 { 
 
\t position: absolute; 
 
\t top: 0em; 
 
\t left: 0; 
 
\t font-size: 4em; 
 
\t width: 100%; 
 
\t color:black; 
 
\t 
 
} 
 
article section h1:hover { 
 
\t text-shadow: 0 998em 2 em #000; 
 
\t transition: text-shadow 1.5s; 
 
\t -webkit-transition: text-shadow 1.5s; 
 
\t -moz-transition:text-shadow 1.5s; 
 
} 
 
nav { 
 
\t display:block; 
 
\t width: 100%; 
 
\t padding: 2em; 
 
\t text-align: center; 
 
} 
 
nav a { 
 
\t color: black; 
 
\t text-decoration: none; 
 
\t padding: 1em 2em; 
 
\t margin-right: 1em; 
 
} 
 
nav > a:hover { 
 
\t border-bottom: .5em solid #c00; 
 
}
<nav> 
 
    \t \t <a href="#first">Option</a> 
 
    \t \t <a href="#second">Option</a> 
 
    \t \t <a href="#third">Option</a> 
 
    \t \t 
 
    \t </nav> 
 
    \t 
 
    \t <article> 
 
    \t \t <section id="first"> 
 
    \t \t \t <h1>First title</h1> 
 
    \t \t </section> 
 
    \t \t <section id="second"> 
 
    \t \t \t <h1>Second title</h1> 
 
    \t \t </section> 
 
    \t \t <section id="third"> 
 
    \t \t \t <h1>Third title</h1> 
 
    \t \t </section> 
 
    \t </article>

fiddle

+0

您的小提琴有缺陷。用那个CSS,你的'部分'永远不会出现,所以你可以看到过渡工作。出于这个原因,你的真实意图还不清楚。请重新编写您的代码,以便我们为您提供帮助。 – VictorGodoi

回答

2

我不知道预期的结果是什么,但无论如何:你在规则有top: -1000em;article section h1,并没有其他的规则,它会改变这个位置。因此这些h1元素将保持隐形状态(因为它们远离屏幕)。将其改为top: 0em;开始,然后查找转换...

+0

你这里有一点,作者的小提琴是有缺陷的。但是这并不能完全回答他的问题。这可能是一个评论。 – VictorGodoi

+2

@VictorGodoi问题不明。唯一的转换是文本阴影转换,但没有触发(悬停或类似)。但是,确切的说,文本无论如何对于给定的设置仍然是不可见的,所以是的,我的回答至少不能解释为什么转换后的文本是不可见的。 – Johannes

+0

你有一点。 – VictorGodoi