TimidObserver
TimidObserver

Reputation: 157

Styling issue with Datalist formatted as Div Table

I am creating a datalist formatted as a table using divs for the formatting. The problem is that the Header of the table is not lining up with the rest of the table.

If I remove the HeaderTemplate, it lines up properly. Any suggestions on how I can fix this?

My Datalist Aspx

<asp:DataList ID="Table1" runat="server" RepeatColumns="1" CellSpacing="1" RepeatLayout="Table">
  <HeaderTemplate>
      <div class="Table">
      <div class="Heading">
          <div class="Cell">
             <p>Heading 1</p>
          </div>
          <div class="Cell">
             <p>Heading 2</p>
          </div>
          <div class="Cell">
             <p>Heading 3</p>
          </div>
          <div class="Cell">
             <p>Heading 4</p>
          </div>
         <div class="Cell">
             <p>Heading 5</p>
         </div>
         <div class="Cell">
             <p>Heading 6</p>
         </div>
         <div class="Cell">
             <p>Heading 7</p>
         </div>
       </div>
</HeaderTemplate>
<ItemTemplate>                    
<div class="Row">
         <div class="Cell">
             <p>Row 1 Column 1</p>
         </div>
         <div class="Cell">
             <p>Row 1 Column 2</p>
         </div>
         <div class="Cell">
             <p>Row 1 Column 3</p>
         </div>
         <div class="Cell">
             <p>Row 1 Column 4</p>
         </div>
         <div class="Cell">
             <p>Row 1 Column 5</p>
         </div>
         <div class="Cell">
             <p>Row 1 Column 6</p>
         </div>
         <div class="Cell">
              <p>Row 1 Column 7</p>
         </div>
      </div>
   </div>
</ItemTemplate>
</asp:DataList>

My CSS

.Table
{
display: table;
}
.Heading
{
display: table-row;
font-weight: bold;
text-align: center;
}
.Row
{
display: table-row;
}
.Cell
{
display: table-cell;
border: solid;
border-width: thin;
padding-left: 5px;
padding-right: 5px;
}

Screenshot of the problem enter image description here

Note: I appreciate any alternative suggestions, but using a Datalist formatted as a table using Divs absolutely with no tables in it is a hard/unchangeable requirement that is completely out of my hands.

Upvotes: 0

Views: 1212

Answers (2)

Francis Nepomuceno
Francis Nepomuceno

Reputation: 5085

Even though you have a HeaderTemplate, in the rendered HTML, the "rows" are not wrapped with <div class="Table">. A possible fix is to simply add width:100%; to the ".Table" class

Upvotes: 0

step
step

Reputation: 186

i hope to help, with this example, although it would be best to put a main div and that contains the elements that form the table

.Table {
  display: table;
  width:100% !important;
}
.Heading {
  display: table-row;
  font-weight: bold;
  text-align: center;
}
.Row {
  display: table;
  width:100% !important;
}
.Cell {
  display: table-cell;
  border: solid;
  border-width: thin;
  padding-left: 5px;
  padding-right: 5px;
}

Upvotes: 1

Related Questions