2010-03-19 19 views
0

我最近一直在研究一個Pastebin腳本(爲了好玩),並且遇到了一個我在CSS中似乎無法解決的問題。我有一個2列的表。 1列用於顯示行號,第2列用於顯示代碼。我似乎無法讓數字與代碼中的行匹配,因此看起來很奇怪(例如:http://www.zamnproductions.com/paste.php?id=32)。看看我的代碼(代碼段):匹配表中2個不同列中的文本?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
    <style type="text/css"> 
     td.num { 
     vertical-align: top; 
     } 
     td.numbers { 
     display:table-cell; 
     padding:1px; 
     vertical-align: top; 
     line-height:25px; 
     } 
     td.code { 
     display:table-cell; 
     vertical-align: top; 
     line-height:20px; 
     } 
     #hide { 
     display:none; 
     } 
     #leftcontent { 
     position: absolute; 
     left:10px; 
     top:119px; 
     width:200px; 
     background:#fff; 
     border:0px solid #000; 
     } 
     #centercontent { 
     background:#fff; 
     margin-left: 199px; 
     margin-right:199px; 
     border:0px solid #000; 
     voice-family: "\"}\""; 
     voice-family: inherit; 
     margin-left: 201px; 
     margin-right:201px; 
     } 
     html>body #centercontent { 
     margin-left: 202px; 
     margin-right:201px; 
     } 
    </style> 

這裏就是表由部分:

<?php 
if (isset($_GET['id'])) { 
$paste = new Paste();?> 
<table border="1"> 
<tr> 
<td class="num"><font size="2"><?php $paste->listNumbers($_GET['id']); ?></font></td> 
<td class="code"><?php $paste->viewCode($_GET['id']); ?></td> 
</tr> 
</table> 
<?php }?> 

回答

2

你得到的表結構是關閉的。

這是您的腳本輸出的內容。

<table border="1"> 
    <tr> 
     <td class="num"> 
      <font size="2"> 
      <table border="0"> 
       <tr> 
        <td class="numbers">1.</td> 
       </tr> 
       <tr> 
        <td class="numbers">2.</td> 
       </tr> 
       [...] 
      </table> 
      </font> 
     </td> 
     <td class="code"> 
      <pre><b>for</b> (<b>int</b> i = 5; i == 5; i++) 
      { 
      System.out.pr<b>int</b>ln(&quot;LOLOL&quot;); 
      }</pre><br/> 
     </td> 
    </tr> 
</table> 

當它應該輸出更多的東西一樣:

<table border="1"> 
    <tr> 
     <td class="num">1.</td> 
     <td class="code"> 
      <pre><b>for</b> (<b>int</b> i = 5; i == 5; i++)</pre> 
     </td> 
    </tr> 
    <tr> 
     <td class="num">2.</td> 
     <td class="code"> 
      <pre>{</pre> 
     </td> 
    </tr> 
</table> 

希望每個錶行由兩列,一個以數字和一個與代碼。你的腳本將所有的數字放入一列中。你應該把代碼分成幾行,然後通過listNumbers進行foreach。

相關問題