php - CSS Sprite 正在恢复为 :hover event due to PHP statementcommentary

标签 php css sprite if-statement

我在我的 wordpress 导航中使用 CSS sprites,为了让它们正常工作,我需要使用 php 来显示该部分的当前页面。

CSS:

#sidebarnav ul#sidenav li.visionside a {width:204px; height:53px; background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/vision2.png)  0px 0}
#sidebarnav ul#sidenav li.visionside a:hover {background-position:0px -53px}


#sidebarnav ul#sidenav li.teamside a {width:204px; height:53px; background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/team2.png)  0px 0}
#sidebarnav ul#sidenav li.teamside a:hover {background-position:0px -53px}


#sidebarnav ul#sidenav li.mtlside a {width:204px; height:53px; background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/mtl2.png)  0px 0}
#sidebarnav ul#sidenav li.mtlside a:hover {background-position:0px -53px}


#sidebarnav ul#sidenav li.blogside a {width:204px; height:53px; background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/content2.png)  0px 0}
#sidebarnav ul#sidenav li.blogside a:hover {background-position:0px -53px}


#sidebarnav ul#sidenav li.orgside a {width:204px; height:53px; background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/org2.png)  0px 0}
#sidebarnav ul#sidenav li.orgside a:hover {background-position:0px -53px}

由 PHP 触发的 Header 中的 CSS:

#sidebarnav ul#sidenav li.<?php echo $current1; ?> {
    background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/vision2.png)  0px -106px;
}

#sidebarnav ul#sidenav li.<?php echo $current2; ?> {
    background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/team2.png)  0px -106px;
}

#sidebarnav ul#sidenav li.<?php echo $current3; ?> {
    background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/content2.png)  0px -106px;
}

#sidebarnav ul#sidenav li.<?php echo $current4; ?> {
    background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/org2.png)  0px -106px;
}

PHP:

 <?php
  if ( is_page('vision') ) { $current1 = 'visionside a'; }
  elseif  ( is_page('team') ) { $current2 = 'teamside a'; }
  elseif  ( is_page('commentary') ) { $current3 = 'blogside a'; }
  elseif  ( is_page('organizations') ) { $current4 = 'orgside a'; }
 ?>

但是当用户将鼠标悬停在导航上时,该元素显示悬停状态,而不是应有的事件状态。

网址:http://jumpthru.net/newsite/vision/

最佳答案

这是一种非常糟糕的做法。忽略常识:

您可以将 !important 添加到每个 background 属性中,例如:

background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/vision2.png)  0px -106px !important;

您的做法与 WordPress 建议的方式有所不同:

http://codex.wordpress.org/Dynamic_Menu_Highlighting

我认为您应该更仔细地阅读该教程,然后重做。

关于php - CSS Sprite 正在恢复为 :hover event due to PHP statementcommentary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6316570/

相关文章:

php - 如何制作字符串数组

php - 一次向 Redis 发出多个请求

jquery - 如何使按钮宽度相同并 float 在中心附近?

jquery - CSS3 过渡仅适用于 Safari 中的第一个元素

c - 我的代码不会显示 Sprite SDL2

html - CSS Sprites - 如何将所有 Sprite 按钮底部对齐

php - 使用明信片图像中的脸部(参见屏幕截图)

php - Symfony - 扩展已注册

html - 倾斜容器内的矩形大小

google-maps-api-3 - Google-Map V3 (Sprite) 中的裁剪标记图标