如何正确对齐这个div内容?

时间:2010-04-03 05:05:02

标签: css html alignment

这是我的布局,

Summary view http://img689.imageshack.us/img689/2500/yuidtsum.jpg

我正在使用一个div和多个跨度来获取上面的视图...看看所有行没有正确对齐......

<div class="resultsdiv"><br />
<span style="width:200px;" class="resultName">' + employee.Emp_Name + '</span>
<span class="resultfields" style="padding-left:100px;">Category&nbsp;:</span>&nbsp;
<span class="resultfieldvalues">' + employee.Desig_Name + '</span><br /><br />
<span id="SalaryBasis" class="resultfields">Salary Basis&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.SalaryBasis + '</span>
<span class="resultfields" style="padding-left:25px;">Salary&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.FixedSalary + '</span>
<span style="font-size:110%;font-weight:bolder;padding-left:25px;">Address&nbsp;:</span>&nbsp;
<span class="resultfieldvalues">' + employee.Address + '</span>
</div>

我的css是

.resultsdiv
{
    background-color: #FFF;border-top:solid 1px #ddd; height:50px; border-bottom:solid 1px #ddd; padding-bottom:15px; width:450px; 
}
.resultseven { background-color: #EFF1f1; }
.resultshover { background-color: #F4F2F2; cursor:pointer; }

.resultName
{
    font-size:125%;font-weight:bolder;color:#476275;font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif;
}
.resultfields
{
    font-size:110%;font-weight:bolder;font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif;
}
.resultfieldvalues
{
    color:#476275;font-size:110%;font-weight:bold;font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif;
}

任何建议让它正确对齐....我应该使用divs insted of span来获得这个 正确对齐...

2 个答案:

答案 0 :(得分:4)

在我看来,这是应该在表格中的数据类型。这不是布局,而是表格,重复数据。

答案 1 :(得分:2)

这是一些重写的​​HTML和CSS的粗略剪辑。我没有测试过这个,但它应该让你接近。发布截图,如果它不起作用。

HTML

<div class="resultsdiv">
  <div class="name">' + employee.Emp_Name + '</div>
  <div class="category"><span>Category :</span> ' + employee.Desig_Name + '</div>
  <div class="salary_basis"><span>Salary Basis :</span> ' + employee.SalaryBasis + '</div>
  <div class="salary"><span>Salary :</span> ' + employee.FixedSalary + '</div>
  <div class="address"><span>Address :</span> ' + employee.Address + '</div>
</div>

CSS

.resultsdiv { color: black }
.resultsdiv span { color: #666 }
.resultsdiv { width: 600px}
.resultsdiv div { float: left }
.resultsdiv .name { width: 230px; padding-right 20px; }
.resultsdiv .category { width: 350px }
.resultsdiv .salary_basis { clear: left; width: 180px; padding-right: 20px }
.resultsdiv .salary { width: 180px; padding-right: 20px }
.resultsdiv .address { width: 200px; }