<td> & img & CSS

Résolu/Fermé
maitag Messages postés 2 Date d'inscription vendredi 25 septembre 2009 Statut Membre Dernière intervention 25 septembre 2009 - 25 sept. 2009 à 08:43
 maitag - 1 oct. 2009 à 08:40
Bonjour,

Je débute donc merci d'être indulgent !
Je veux afficher un histogramme. Donc je me crée une table et je met un graphique dans chaque cellule dont je module la hauteur en fonction de la valeur. Ce qui donne :

<table id="GraphBar">
<tr>
<th>titre</th>
<td id="B0">10<img src="col.gif" width="14" height="10" alt="" /></td>
<td id="B1">21<img src="col.gif" width="14" height="21" alt="" /></td>
<td id="B2">39<img src="col.gif" width="14" height="39" alt="" /></td>
<td id="B3">17<img src="col.gif" width="14" height="17" alt="" /></td>
</tr>
<tr>
<th></th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</table>

Ensuite, je voudrais un peu optimiser le truc car je répète à chaque fois une image pour chaque cellule.
Je pensais m'en sortir avec du CSS mais rien de marche. En particulier, le code ci-dessous ne donne rien :

<style>
.bargraph img{
display:block
border-right: 2px solid #FFFFFF;
border-top: 2px solid #FFFFFF;
img-src:url(col.gif)>
}
</style>

<table id="GraphBar" class="bargraph">
<tr>
<th>titre</th>
<td id="B0">10</td>
<td id="B1">21</td>
<td id="B2">39</td>
<td id="B3">17</td>
</tr>
<tr>
<th></th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</table>

Question1 : est-il possible mettre l'image d'un TD dans du CSS ? Si oui, comment ?
Question2 : je voudrais modifier la hauteur d'une barre de mon histogramme en JS mais je n'y arrive pas. Voici le code que j'utilise (et qui ne donne rien) :

function UpdateData()
{
for (var i=0; i<4;i++) {
document.getElementById("B"+i).height = i*10 + "px";
}
}

Quelqu'un a une solution ?

Merci pour vos réponses !

2 réponses

jjsteing Messages postés 1669 Date d'inscription vendredi 11 mai 2007 Statut Contributeur Dernière intervention 21 mai 2012 181
25 sept. 2009 à 11:39
re :)

bon, pour l image en fond :

<style>
.bargraph td{
display:block
border-right: 2px solid #FFFFFF;
border-top: 2px solid #FFFFFF;
background-image:url(col.gif);>
}
</style>


et non .bargraph img{ car tu n as pas de balise img ;) ceci va mettre l arriere plan de la case avec ton image mais cela rempliera tout l arrire plan, hors, ce que j ais compris, c'est que tu veux faire un graphique.. donc :

voici une partie de la solution :

<style>
.bargraphimg{
border: solid 2px green ;
background-image:url(col.gif);
}
</style>

<table id="GraphBar" class="bargraph" STYLE="vertical-align:bottom" BORDER>
<tr>
<th>titre</th>
<td VALIGN="bottom" id="B0" ><div class="bargraphimg" STYLE="height:10px;"></div>10</td>
<td VALIGN="bottom" id="B1" ><div class="bargraphimg" STYLE="height:21px;" ></div>21</td>
<td VALIGN="bottom" id="B2" ><div class="bargraphimg" STYLE="height:39px;" ></div>39</td>
<td VALIGN="bottom" id="B3" ><div class="bargraphimg" STYLE="height:17px;" ></div>17</td>
</tr>
<tr>
<th></th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</table>

tu trouvera un exemple en ligne.. toujours sur mon site jjsteing.u7n.org => wenbmastering => Graphique
1
Super !
Merci à toi.
0
jjsteing Messages postés 1669 Date d'inscription vendredi 11 mai 2007 Statut Contributeur Dernière intervention 21 mai 2012 181
25 sept. 2009 à 09:37
Bonjour...

Bon déjà :
img-src:url(col.gif) ca n existe pas !!! remplace par :

background-image:url(col.gif);
0
maitag Messages postés 2 Date d'inscription vendredi 25 septembre 2009 Statut Membre Dernière intervention 25 septembre 2009
25 sept. 2009 à 10:24
OK. J'ai corrigé la syntaxe.
Mais toujours pas d'image qui s'affiche dans les cellules...
0