我的page.tpl.php有一个标准的h1标签:
<h1><?php print $title ?></h1>
一切都很好,但是,我想使用一个图像来样式我的H1标签的字体。这一切都很好,但这些都是唯一的,所以我需要添加一个类到h1标签,这样我所有的主要部分都是唯一的。
我的想法是使用php在每个主页上抓取一些独特的东西…URL是唯一的,所以我选择:
<div class="<?php print $current_path = drupal_get_path_alias($_GET["q"]);?>"><h1><?php print $title ?></h1></div>
这工作得很好,我甚至不知道php!但是! !我的一些url中有数字,它们在页面代码中打印得很好,但css不会与它们通信:(
<div class="books-and-toys"><h1><?php print $title ?></h1></div>
但是,这不会style:
<div class="70s-books-and-toys"><h1><?php print $title ?></h1></div>
那么,有没有人知道我怎么才能绕过这个,或者实际上,我的页面有什么独特的地方,这样我就可以打印一些东西来制作div id?
非常感谢您的帮助
据我所知,至少在css2中。在x中,所有类名必须以-
、_
或字母a-z
开头。因此,70s-
将不是一个有效的类名。
一个快速的解决办法是在类的前面加上:
<div class="<?php print 'title-' . $current_path = drupal_get_path_alias($_GET["q"]);?>">
<h1><?php print $title ?></h1>
</div>
您还可以通过以下方式消除这个额外的div:
<h1 class="<?php print 'title-' . $current_path = drupal_get_path_alias($_GET["q"]);?>">
<?php print $title ?>
</h1>
但是DIV很好;特别是如果你想在header中添加样式