Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1185 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Tableau dans un div qui permet de scroller le contenu, pas l'en-tête.

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Tableau dans un div qui permet de scroller le contenu, pas l'en-tête.

n°1509681
ugopetit
Posté le 01-02-2007 à 16:33:05  profilanswer
 

Bonjour, j'utilise le source suivant pour permettre d'éviter que le titre d'un tableau scrolle avec son contenu.
 

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <script type="text/javascript">
  3. <!--
  4. function removeClassName (elem, className) {
  5. elem.className = elem.className.replace(className, "" ).trim();
  6. }
  7. function addCSSClass (elem, className) {
  8. removeClassName (elem, className);
  9. elem.className = (elem.className + " " + className).trim();
  10. }
  11. String.prototype.trim = function() {
  12. return this.replace( /^\s+|\s+$/, "" );
  13. }
  14. function stripedTable() {
  15. if (document.getElementById && document.getElementsByTagName) { 
  16.  var allTables = document.getElementsByTagName('table');
  17.  if (!allTables) { return; }
  18.  for (var i = 0; i < allTables.length; i++) {
  19.   if (allTables[i].className.match(/[\w\s ]*scrollTable[\w\s ]*/)) {
  20.    var trs = allTables[i].getElementsByTagName("tr" );
  21.    for (var j = 0; j < trs.length; j++) {
  22.     removeClassName(trs[j], 'alternateRow');
  23.     addCSSClass(trs[j], 'normalRow');
  24.    }
  25.    for (var k = 0; k < trs.length; k += 2) {
  26.     removeClassName(trs[k], 'normalRow');
  27.     addCSSClass(trs[k], 'alternateRow');
  28.    }
  29.   }
  30.  }
  31. }
  32. }
  33. window.onload = function() { stripedTable(); }
  34. -->
  35. </script>
  36. <style type="text/css">
  37. <!--
  38. /* begin some basic styling here                     */
  39. body {
  40. background: #FFF;
  41. color: #000;
  42. font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
  43. margin: 10px;
  44. padding: 0
  45. }
  46. table, td, a {
  47. color: #000;
  48. font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
  49. }
  50. h1 {
  51. font: normal normal 18px Verdana, Geneva, Arial, Helvetica, sans-serif;
  52. margin: 0 0 5px 0
  53. }
  54. h2 {
  55. font: normal normal 16px Verdana, Geneva, Arial, Helvetica, sans-serif;
  56. margin: 0 0 5px 0
  57. }
  58. h3 {
  59. font: normal normal 13px Verdana, Geneva, Arial, Helvetica, sans-serif;
  60. color: #008000;
  61. margin: 0 0 15px 0
  62. }
  63. /* end basic styling                                 */
  64. /* define height and width of scrollable area. Add 16px to width for scrollbar          */
  65. div.tableContainer {
  66. clear: both;
  67. border: 1px solid #963;
  68. height: 285px;
  69. overflow: auto;
  70. width: 756px
  71. }
  72. /* Reset overflow value to hidden for all non-IE browsers. */
  73. html>body div.tableContainer {
  74. overflow: hidden;
  75. width: 756px
  76. }
  77. /* define width of table. IE browsers only                 */
  78. div.tableContainer table {
  79. float: left;
  80. width: 740px
  81. }
  82. /* define width of table. Add 16px to width for scrollbar.           */
  83. /* All other non-IE browsers.                                        */
  84. html>body div.tableContainer table {
  85. width: 756px
  86. }
  87. /* set table header to a fixed position. WinIE 6.x only                                       */
  88. /* In WinIE 6.x, any element with a position property set to relative and is a child of       */
  89. /* an element that has an overflow property set, the relative value translates into fixed.    */
  90. /* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
  91. thead.fixedHeader tr {
  92. position: relative
  93. }
  94. /* set THEAD element to have block level attributes. All other non-IE browsers            */
  95. /* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
  96. html>body thead.fixedHeader tr {
  97. display: block
  98. }
  99. /* make the TH elements pretty */
  100. thead.fixedHeader th {
  101. background: #C96;
  102. border-left: 1px solid #EB8;
  103. border-right: 1px solid #B74;
  104. border-top: 1px solid #EB8;
  105. font-weight: normal;
  106. padding: 4px 3px;
  107. text-align: left
  108. }
  109. /* make the A elements pretty. makes for nice clickable headers                */
  110. thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
  111. color: #FFF;
  112. display: block;
  113. text-decoration: none;
  114. width: 100%
  115. }
  116. /* make the A elements pretty. makes for nice clickable headers                */
  117. /* WARNING: swapping the background on hover may cause problems in WinIE 6.x   */
  118. thead.fixedHeader a:hover {
  119. color: #FFF;
  120. text-decoration: underline;
  121. width: 100%
  122. }
  123. /* define the table content to be scrollable                                              */
  124. /* set TBODY element to have block level attributes. All other non-IE browsers            */
  125. /* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
  126. /* induced side effect is that child TDs no longer accept width: auto                     */
  127. html>body tbody.scrollContent {
  128. height: 262px;
  129. overflow: auto;
  130. width: 100%
  131. }
  132. /* make TD elements pretty. Provide alternating classes for striping the table */
  133. tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
  134. background: #FFF;
  135. border-bottom: none;
  136. border-left: none;
  137. border-right: 1px solid #CCC;
  138. border-top: 1px solid #DDD;
  139. padding: 2px 3px 3px 4px
  140. }
  141. tbody.scrollContent tr.alternateRow td {
  142. background: #EEE;
  143. border-bottom: none;
  144. border-left: none;
  145. border-right: 1px solid #CCC;
  146. border-top: 1px solid #DDD;
  147. padding: 2px 3px 3px 4px
  148. }
  149. /* define width of TH elements: 1st, 2nd, and 3rd respectively.          */
  150. /* Add 16px to last TH for scrollbar padding. All other non-IE browsers. */
  151. html>body thead.fixedHeader th {
  152. width: 200px
  153. }
  154. html>body thead.fixedHeader th + th {
  155. width: 240px
  156. }
  157. html>body thead.fixedHeader th + th + th {
  158. width: 316px
  159. }
  160. /* define width of TD elements: 1st, 2nd, and 3rd respectively.          */
  161. /* All other non-IE browsers.                                            */
  162. html>body tbody.scrollContent td {
  163. width: 200px
  164. }
  165. html>body tbody.scrollContent td + td {
  166. width: 240px
  167. }
  168. html>body tbody.scrollContent td + td + td {
  169. width: 300px
  170. }
  171. -->
  172. </style>
  173. </head><body>
  174. <h1>Pure CSS Scrollable Table with Fixed Header</h1>
  175. <h2>Using CSS to allow scrolling within a single HTML table</h2>
  176. <div><br/></div>
  177. <h2>The Big 4 Version</h2>
  178. <h3>Basic CSS Browser Filtering</h3>
  179. <div id="tableContainer" class="tableContainer">
  180. <table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
  181. <thead class="fixedHeader">
  182. <tr>
  183.  <th><a href="#">Header 1</a></th>
  184.  <th><a href="#">Header 2</a></th>
  185.  <th><a href="#">Header 3</a></th>
  186. </tr>
  187. </thead>
  188. <tbody class="scrollContent">
  189. <tr>
  190.  <td>Cell Content 1</td>
  191.  <td>Cell Content 2</td>
  192.  <td>Cell Content 3</td>
  193. </tr>
  194. <tr>
  195.  <td>More Cell Content 1</td>
  196.  <td>More Cell Content 2</td>
  197.  <td>More Cell Content 3</td>
  198. </tr>
  199. <tr>
  200.  <td>Cell Content 1</td>
  201.  <td>Cell Content 2</td>
  202.  <td>Cell Content 3</td>
  203. </tr>
  204. <tr>
  205.  <td>More Cell Content 1</td>
  206.  <td>More Cell Content 2</td>
  207.  <td>More Cell Content 3</td>
  208. </tr>
  209. <tr>
  210.  <td>Cell Content 1</td>
  211.  <td>Cell Content 2</td>
  212.  <td>Cell Content 3</td>
  213. </tr>
  214. <tr>
  215.  <td>More Cell Content 1</td>
  216.  <td>More Cell Content 2</td>
  217.  <td>More Cell Content 3</td>
  218. </tr>
  219. <tr>
  220.  <td>Cell Content 1</td>
  221.  <td>Cell Content 2</td>
  222.  <td>Cell Content 3</td>
  223. </tr>
  224. <tr>
  225.  <td>More Cell Content 1</td>
  226.  <td>More Cell Content 2</td>
  227.  <td>More Cell Content 3</td>
  228. </tr>
  229. <tr>
  230.  <td>Cell Content 1</td>
  231.  <td>Cell Content 2</td>
  232.  <td>Cell Content 3</td>
  233. </tr>
  234. <tr>
  235.  <td>More Cell Content 1</td>
  236.  <td>More Cell Content 2</td>
  237.  <td>More Cell Content 3</td>
  238. </tr>
  239. <tr>
  240.  <td>Cell Content 1</td>
  241.  <td>Cell Content 2</td>
  242.  <td>Cell Content 3</td>
  243. </tr>
  244. <tr>
  245.  <td>More Cell Content 1</td>
  246.  <td>More Cell Content 2</td>
  247.  <td>More Cell Content 3</td>
  248. </tr>
  249. <tr>
  250.  <td>Cell Content 1</td>
  251.  <td>Cell Content 2</td>
  252.  <td>Cell Content 3</td>
  253. </tr>
  254. <tr>
  255.  <td>More Cell Content 1</td>
  256.  <td>More Cell Content 2</td>
  257.  <td>More Cell Content 3</td>
  258. </tr>
  259. <tr>
  260.  <td>Cell Content 1</td>
  261.  <td>Cell Content 2</td>
  262.  <td>Cell Content 3</td>
  263. </tr>
  264. <tr>
  265.  <td>More Cell Content 1</td>
  266.  <td>More Cell Content 2</td>
  267.  <td>More Cell Content 3</td>
  268. </tr>
  269. <tr>
  270.  <td>Cell Content 1</td>
  271.  <td>Cell Content 2</td>
  272.  <td>Cell Content 3</td>
  273. </tr>
  274. <tr>
  275.  <td>More Cell Content 1</td>
  276.  <td>More Cell Content 2</td>
  277.  <td>More Cell Content 3</td>
  278. <td style="visibility:'hidden'">More Cell Content 1</td>
  279. </tr>
  280. </tbody>
  281. </table>
  282. </div>
  283. </body></html>


 
Mais j'ai le problème suivant : je ne peux pas éviter l'affichage des cases ayant style="display:'none'"
 
Et autre chose : chez moi, le titre "s'envole" lorsque je scrolle le contenu du tableau avec la molette..., mais cela vient du contexte dans lequel j'ai incrusté ce code. Je suis sous IE et mon tableau est dans un div qui est lui même dans un autre tableau.
 
Des idées?
Merci d'avance.


---------------
programmeur : "Personne qui résoud, de manière incompréhensible, un problème dont tu ignorais même l'existence..."  Pierre Desproges.
mood
Publicité
Posté le 01-02-2007 à 16:33:05  profilanswer
 

n°1509932
ugopetit
Posté le 02-02-2007 à 10:21:01  profilanswer
 

Bon, le souci d'affichage des colonnes, c'est a cause de ma manie à la c** de mettre des quotes partout...
 
Mais le pb de l'entete qui part vers le haut, ca c'est moyen...
Le contexte dont je parlais, c'est qu'en fait j'ai deja d'autres styles qui sont utilisées sur d'autres composants de ma page...
 
En fait je sais pourquoi l'en-tête se déplace comme ca, c'est parce que dans mon tableau, chaque ligne dispose d'un style particulier, avec en plus un rollover(appelés avec onmouseover et onmouseout)
Comment pallier à ce problème?
Help please!


Message édité par ugopetit le 02-02-2007 à 13:26:06

---------------
programmeur : "Personne qui résoud, de manière incompréhensible, un problème dont tu ignorais même l'existence..."  Pierre Desproges.
n°1510156
ugopetit
Posté le 02-02-2007 à 15:57:22  profilanswer
 

Merci a tous pour vos réponses  :sweat:  
Bref, je me suis débrouillé tout seul.
ciao les amis...


---------------
programmeur : "Personne qui résoud, de manière incompréhensible, un problème dont tu ignorais même l'existence..."  Pierre Desproges.
n°1511447
PunkRod
Digital Mohawk
Posté le 06-02-2007 à 16:03:34  profilanswer
 

A mon avis la réponse est dans la fonction css "overfllow", ou alors j'ai pas compris l'exposé du problème.


Message édité par PunkRod le 06-02-2007 à 16:03:47

---------------
Assistants SWGOH
n°1511528
Krueger
tout salaire demande dutravail
Posté le 06-02-2007 à 18:27:11  profilanswer
 

< à supprimer car tu as utilisé ce que j'allais te conseiller :D >


Message édité par Krueger le 06-02-2007 à 18:29:24
n°1511732
ugopetit
Posté le 07-02-2007 à 10:54:50  profilanswer
 

En fait , le rollover que je fais sur chaque ligne du tableau change la couleur du texte, du background et des bordures des cases.
Et le fait de changer la couleur des bordures fout le bordel, enfin fait scroller l'en-tête(mais quand je dis scroller, ce n'est pas qu'elle disparait dans le div non non, elle se promenait SUR ma page...).
En même temps c'est sûrement du à IE, mais je ne veux pas faire ma mauvaise langue...


---------------
programmeur : "Personne qui résoud, de manière incompréhensible, un problème dont tu ignorais même l'existence..."  Pierre Desproges.
n°1773255
vixell
Posté le 14-08-2008 à 12:23:54  profilanswer
 

bonjour,  
 
Je me suis appuyé sur le code que vous avez écrit pour concevoir une liste déroulante avec header figée.
Nota : la différence consiste à ce que la hauteur des données variées selon la taille de la fenêtre grace à des fonctions javascript.
 
ma page est accessible à l'adresse http://www.vixellmailer.com/test2.php
 
(Tout le code est accessible par click droit, les données ne sont pas dynamiques dans cette page d'exemple.)
 
Sur Firefox, tout marche nickel. Sous IE, le scroll ne fonctionne pas.
 
Pouvez vous m'aider svp à faire fonctionner cette page sous IE ?
 
Merci.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Tableau dans un div qui permet de scroller le contenu, pas l'en-tête.

 

Sujets relatifs
Tableau avec ombre en bas et à droite[C] Construire un tableau à partir d'un fichier
[PHP] Recherche d'un module pour création de tableau du style ExcelRetour arrière sur un formulaire sans effacer le contenu.
Apparence d'un tableau...?? (pointillés)faire tableau avec des donnees recuperees d'un file xml
Tableau IE/FFPasser un tableau ou une hash Perl à JavaScript
Tableau impossible à afficher dans le haut absolu de la page 
Plus de sujets relatifs à : Tableau dans un div qui permet de scroller le contenu, pas l'en-tête.


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR