douwaif22244 2012-10-29 18:43
浏览 39

使用奇数和偶数类交替评论颜色

I asked this question earlier but had no luck with responses. :(

I have the new WordPress 2.7 Comments Loop, and I know you can simply add .odd and .even to your CSS to get alternating comment colours, which I've done:

.odd { background: #ccc; color: #000; }
.even { background: #bbb; color: #000; }

However, I have two different backgrounds - a light and a dark one - that the user can choose from the options panel. Therefore I need two different versions of the odd and even classes so I can have different colours for each, as the above background colours look nice against the light background but not so good against the dark one.

But with the 2.7 Comments Loop, the odd and even classes aren't actually there in the code. If they were, I'd have done something like this:

$background = get_option('mytheme_background');
if ($background== "option1") { echo '<div class="odd-dark">'; } 
if ($background== "option1") { echo '<div class="even-dark">'; }
if ($background== "option2") { echo '<div class="odd-light">'; } 
if ($background== "option2") { echo '<div class="even-light">'; }

So with .odd and .even not actually being there in the code, how can I go about having two different .odd and .even versions in the CSS?

  • 写回答

2条回答 默认 最新

  • doucao1066 2012-10-29 18:51
    关注

    PHP:

    $background = get_option('mytheme_background');
    // no more - between class names to use specializations of odd/even in CSS
    if ($background== "option1") { echo '<div class="odd dark">'; } 
    if ($background== "option1") { echo '<div class="even dark">'; }
    if ($background== "option2") { echo '<div class="odd light">'; } 
    if ($background== "option2") { echo '<div class="even light">'; }
    

    AND CSS:

    /* now specialize 2 variants for each type odd/even * dark/light */
    .odd.light { background: #ccc; color: #000; }
    .even.light { background: #bbb; color: #000; }
    .odd.dark { background: #ccc; color: #000; }
    .even.dark { background: #bbb; color: #000; }
    

    Try this.

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法