这是我的布局,
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;
}

任何让它正确对齐的建议。。。。我应该用div代替spans来得到这个
正确对齐。。。

最佳答案

下面是一些重写的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; }

关于css - 如何正确对齐此div内容?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2570285/

10-09 13:14