2011-04-13 49 views
0

我試圖找到一種方法來使我的td或表多種顏色。html/php中的多色TD?

echo "<table padding=\"0\" spacing=\"0\" 
    style=\"background-color:yellow; width: 100%; margin-left: 2px; 
    width: 100%; line-height: 80% ;\">"; 
echo "<tr>"; 
echo "<td class=\"bgfiller\"> 
    <font style=\"color: black; font-size:90%; \" > 
    ".$rowbis['Lnaam']." - ".$rowbis['Type_name']."</font> 
    </td></tr>"; 

我bgfiller風格看起來是這樣的:

.bgfiller{ 
    width: 10px; 
    background-color: red; 
    z-index: 1 ; 
} 

所以我想要做的是使一個塊是黃色的小方塊在它10px的的(將被設置在稍後的狀態中變量)並且在其上覆蓋一些文本。

所以你會得到一個像文本的進度條。但是文本必須使用表格的完整寬度並且只使用10px。

任何人都知道如何讓這個工作?

+0

我極力推薦使用像jQuery,Dojo,Prototype,MooTools等Javascript庫,它們都包含諸如開箱即用的東西。 – 2011-04-13 20:37:15

+0

這樣的事情? http://jsfiddle.net/3mGfC/ – stealthyninja 2011-04-13 20:42:07

+0

@ daemonfire300當基本的CSS可以做時,真的不需要JavaScript。 JavaScript程序庫非常適合JavaScript編程。不適用於基本的頁面佈局和程式。 – VoteyDisciple 2011-04-13 20:51:22

回答

1

首先,請刪除<font>標籤。當您只需將font-size: 90%; color: black;添加到您現有的.bgfiller規則中就沒有理由。

但是,爲了回答你的問題,我建議是這樣的:

<div style="width: 200px; border: 1px solid black; position: relative;"> 
    Hello There I am Text 
    <div style="width: 30px; background: yellow; position: absolute; left: 0; top: 0; z-index: -1;">&nbsp;</div> 
</div> 

參見:http://jsfiddle.net/knWuf/

+1

並且不要使用表格進行佈局,它們用於數據表格。 – 2011-04-13 20:32:08

1

像這樣的東西是乾淨多了,但究竟什麼是你想用文字來呢?

演示:http://jsfiddle.net/WVvLD/

<div><span>Progress</span><div> 
div { 
    background-color: yellow; 
} 
span { 
    background-color: red; 
    display:block; 
    width: 10px; 
} 
0

如果你想保持與表工作,這可能是一個解決方案:

<table width="100%"> 
<tr> 
     <td><span></span>this is an text</td>  
</tr> 
</table> 

和風格

td{ 
background-color:green; 
    width:100%; 
    position:relative; 
    z-index:-2; 
} 
td span{ 
    position:absolute; 
    width:20px; 
    height:20px; 
    background-color:darkred; 
    z-index:-1; 
} 

http://jsfiddle.net/WVvLD/34/