我已经使用了该网站上的搜索功能并进行了谷歌搜索,但没有找到明确的答案。希望有人能够为我指明正确的方向。
我在 PHP 打印语句中设置链接样式如下:
print '<a href="'.$linkPath.'index.php" style="color:white">Home</a> | <a href="'.$linkPath.'scripts/login.php" style="color:white">Login</a>'. PHP_EOL;
这对我有用,但是提供的代码只是一个简短的示例,我还有几个链接。
考虑到这属于重复的代码冗余类别
style="color:white"
我正在寻找另一种解决方案。
在这种情况下可以使用循环吗?如果可以,有人可以举例说明我如何编写它吗?
如何为我的链接添加样式而不必为每个链接明确指定它?
最佳答案
不要使用内联样式。改用 CSS 类,就像这样
print '<a href="'.$linkPath.'index.php" class="white">Home</a> | <a href="'.$linkPath.'scripts/login.php" class="white">Login</a>'. PHP_EOL;
在你的 CSS 中
.white{
color:white;
}
如果你真的想避免任何代码冗余,你可以使用 CSS 伪选择器
#div>a{
color:white;
}
关于php - 在多个打印的 href 中打印 CSS 样式的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20905775/