【问题标题】:how to change a link depending on body ID如何根据正文 ID 更改链接
【发布时间】:2015-03-24 13:35:17
【问题描述】:

我需要根据页面的类别更改网站标题上的链接。目前我们正在使用 php 的 switch/case/break 来根据类别切换整个“a href ...etc”链接,例如:

case 'red': ?>
<a href="red.html">red</a>
<?php break;
case 'blue': ?>
<a href="blue.html"></a>

等等。

有没有办法用 css 和 body id 做到这一点?示例:body id="red",除 php 或 javascript 之外的其他内容可能会更改链接,例如 css 的 content:before 或 :after?我不知道如何将其应用于 a 标签内。谢谢。

【问题讨论】:

  • 你能给我们看一些代码吗,我不确定你在问什么?你想改变样式还是href-Attribute
  • 抱歉,已编辑。因此,如果可能的话,我想做的是根据正文 id 在链接的 href 中更改 .html 之前的单词,而不使用 php 或 javascript。
  • css-tricks.com/css-content 在Using Attributes 下查看,但是你为什么不想使用PHP?如果你用 CSS 来做,你会把内容和设计混在一起,这不是一件好事

标签: php html css


【解决方案1】:

你为什么不这样做:

$category = "red"
<a href="<?=$category;?>.html"></a>

如果您想要 CSS 解决方案,我会导入一个“主题”文件,例如:

category_red.css category_blue.css

在页面的顶部,我会调用所需的类别:

<link rel="stylesheet" type="text/css" href="category_red.css">

【讨论】:

  • 嗯,$category = "red" 听起来是个不错的选择,谢谢!如果我要使用 css 主题,我会在可以更改链接的主题中添加什么?
  • 我会自定义标签并创建将在我的网站上使用的类,例如:主题“红色”,CSS 将是 {color:red;} 等等。一个类的例子是 .link_color{color:red;} 然后是 link
猜你喜欢
  • 1970-01-01
  • 2011-01-23
  • 2016-11-13
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多