2011-11-23 28 views
1

Page contentCSS StylesheetCSS:使用寬度百分比定位子表?

當您訪問頁面內容鏈接時,請拿下面的示例代碼並提交它。您會注意到子表source_code沒有一直延伸到右側。如果我將width: 100%添加到syntax_table類中,它可以解決問題,但source_code表正確對齊,我無法將其移動到左側。

我花了大約2個小時試圖解決它,我現在需要一些幫助。

下面是一些C#示例代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 

namespace Test1 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 
     } 

     /// <summary> 
     /// Calculate method. 
     /// </summary> 
     /// <param name="sender">Sender</param> 
     /// <param name="e">Event Arguments</param> 
     private void btnCalculate_Click(object sender, RoutedEventArgs e) 
     { 
      double weight; 
      int heightf, heighti; 

      Double.TryParse(this.txtWeight.Text, out weight); 
      Int32.TryParse(this.txtHeightF.Text, out heightf); 
      Int32.TryParse(this.txtHeightI.Text, out heighti); 

      if (!(heightf >= 1)) 
       MessageBox.Show("A person is at least 1 foot tall."); 
      else if (!(weight >= 1.0)) 
       MessageBox.Show("A person cannot weigh nothing."); 
      else if (heightf >= 12) 
       MessageBox.Show("A person is not taller than 12 feet."); 
      else 
      { 
       double kg = weight * 0.45359237; 
       int height = heighti + (heightf * 12); 
       double bmi = weight/(height * height) * 703; 
       double gbmi = Math.Round(bmi, 1); 
       this.txtBMI.Text = bmi.ToString("n1"); 
      } 
     } 
    } 
} 
+0

重讀原來,我不認爲我完全理解這個問題 - 您可以發佈生成的HTML/CSS代碼,所以我可以把它放在一個頁面,然後看到問題在發揮? 謝謝! – Dracorat

回答

1

這是因爲在.syntax_table 2個表格單元格的大小本身,你的瀏覽器是要猜。您需要至少設置表格單元格的寬度含line_numbers

<table class="syntax_table"> 
    <tr> 
      <td class="lines"><table class="line_numbers">...</table></td> 
      <td><table class="source_code">...</table></td> 
    </tr> 
</table> 

樣式

.source_code { width: 100%; } // add this to give source_code full width of it's cell 
.lines { width: 50px } // or set to a percentage, then .code should take up the rest 
+0

謝謝,通過在單元格和表格本身上爲「line_numbers」設置寬度爲50px,它已經解決了問題。 –