【问题标题】:CSS: Positioning child table using width percentage?CSS:使用宽度百分比定位子表?
【发布时间】:2011-11-23 15:16:22
【问题描述】:

Page content, CSS Stylesheet

当您访问页面内容链接时,请获取下面的示例代码并提交。您会注意到子表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");
            }
        }
    }
}

【问题讨论】:

  • 重读原文,我认为我没有完全理解这个问题 - 你能发布生成的 HTML/CSS 代码,这样我就可以把它放在一个页面中,然后看看问题所在吗?谢谢!

标签: c# css width syntax-highlighting


【解决方案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

【讨论】:

  • 谢谢,通过将line_numbers 的单元格和表格本身的宽度设置为 50px,它已经解决了问题。
猜你喜欢
  • 2013-07-23
  • 2013-08-23
  • 2018-01-06
  • 2012-09-05
  • 2013-11-01
  • 1970-01-01
  • 2016-07-15
  • 2015-09-29
相关资源
最近更新 更多