Search code examples
csshtmlalignment

How to align this div contents properly?


Here is my layout,

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

I am using one div and many spans for getting the above view... Look at all the rows ther are not properly aligned...

<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>

and my css are

.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;
}

Any suggestion to get it aligned properly.... Should i use divs insted of spans to get this properly aligned...


Solution

  • Here is a rough cut of some rewritten HTML and CSS. I have not tested this, but it should get you close. Post a screenshot if it doesn't work.

    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; }