2017-03-04 147 views
1

我想要替代行顏色,但只有子彈點是交替顏色在http://althedge.xyz有人可以告訴我如何做到這一點? 謝謝替代行顏色UL LI

我在下面使用這個css代碼來替代子彈點顏色,但如何交替行顏色。

ul:nth-of-type(odd) { 
    color: #ccc; 
} 

PHP文件

<?php 
// Database Settings 
define('DB_HOST', 'localhost'); 
define('DB_PORT', '*****'); 
define('DB_USER', '*****'); 
define('DB_PASS', '*****'); 
define('DB_NAME', '*****'); 

// Connection to Database 
$database = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); 

$sql = 'SELECT * ' 
     . ' FROM crypto ORDER BY Date DESC, Number DESC'; 

$resultSet = $database->query($sql); 

$currentDate = false; 
while ($row = $resultSet->fetch_assoc()) { 
    if ($row['Date'] != $currentDate) { 
     echo $row['Date'] ; 
     $currentDate = $row['Date']; 
    } 

    echo '<ul><li>' . 
    '<A HREF="'. 
    $row["Link"]. 
    '"style="text-decoration: none;"'. 
    '">'. 
    $row["Article"]. 
    '</A>'. 
    '</li></ul>'; 
} 

$html .= '</table>'; 
echo $html; 
?> 

回答

0

首先,你要移動<ul>呼應while循環之外。您只需要一個<ul>元素包裝所有<li>的元素。這可能是故意的,但我認爲我應該告訴你。

接下來,您提供的CSS將針對<ul>元素本身,而不是其內部的標記。最後,錨點元素在Web瀏覽器中具有默認樣式 - 這就是爲什麼他們目前是藍色的。

ul li:nth-of-type(odd) a { 
 
    color: #ccc; 
 
}
<ul> 
 
\t <li> 
 
\t \t <a href="http://www.coindesk.com/ether-prices-surge-shadow-bitcoin-dash/" style="text-decoration: none;">dash bubble overshadows ethereum upswing...</a> 
 
\t </li> 
 
\t <li> 
 
\t \t <a href="https://www.reddit.com/r/ethtrader/comments/5xdcv8/asia_is_late_to_the_party_%E4%BA%9A%E6%B4%B2%E6%99%9A%E5%88%B0%E6%99%9A%E4%BC%9A/" style="text-decoration: none;">ethereum rises despite absent eth/cny markets...</a> 
 
\t </li> 
 
\t <li> 
 
\t \t <a href="https://news.vice.com/story/bitcoins-are-more-expensive-than-gold-now-thanks-china" style="text-decoration: none;">is the devalued yuan moving bitcoin...</a> 
 
\t </li> 
 
\t <li> 
 
\t \t <a href="http://fortune.com/2017/03/03/bitcoin-pricing-record/" style="text-decoration: none;">traders optimistic about the etf...</a> 
 
\t </li> 
 
</ul>

+0

不錯,我搞砸了,我真正的意思是有行背景替代顏色..對不起......任何想法如何做到這一點?謝謝 – vinman64

+0

是的,只需將該CSS片段更改爲: ul li:第n種(奇數){ background-color:#ccc; } – Leland

0

查看你的代碼,顏色從a標籤,你可以改變你的CSS這種方式來解決它

ul:nth-of-type(odd), 
ul:nth-of-type(odd) a { 
    color: #ccc; 
} 
+0

嗨,它的偉大工程,除了我必須解釋是錯誤的。我想要背景顏色交替,而不是字體。任何想法如何做到這一點?謝謝 – vinman64

0

你可以做這通過簡單的CSS:

ul li { 
    color: blue; 
} 
ul li:nth-child(odd) { 
    color: grey; 
} 
0

藍色是默認鏈接的顏色,你需要改變顏色的鏈接

ul:nth-of-type(odd) a { 
    color: #ccc; 
} 
0
<?php 
// Database Settings 
define('DB_HOST', 'localhost'); 
define('DB_PORT', '*****'); 
define('DB_USER', '*****'); 
define('DB_PASS', '*****'); 
define('DB_NAME', '*****'); 

// Connection to Database 
$database = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); 

$sql = 'SELECT * ' 
     . ' FROM crypto ORDER BY Date DESC, Number DESC'; 

$resultSet = $database->query($sql); 

$currentDate = false; 
echo "<ul>"; 
while ($row = $resultSet->fetch_assoc()) { 
    if ($row['Date'] != $currentDate) { 
     echo $row['Date'] ; 
     $currentDate = $row['Date']; 
    } 

    echo '<li>' . 
    '<A HREF="'. 
    $row["Link"]. 
    '"style="text-decoration: none;"'. 
    '">'. 
    $row["Article"]. 
    '</A>'. 
    '</li>'; 
} 
echo "</ul>"; 
$html .= '</table>'; 
echo $html; 
?>