10 November 2016

HTML Table as Div

Below illustrates how we can use Div to display table content. Essentially just use css clear:left as the beginning of each row and css float:left for table cell
@using WebApplication2.Models
@model Product[]
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>

<body>
    <style>
        .body{
            font-family:Tahoma;
            font-size:10pt;
        }
        .TableLabel {
            width: 200px;
            min-width: 200px;
            max-width: 200px;
            background-color:powderblue;
        }
        .TableContent {
            width: 200px;
            min-width: 200px;
            max-width: 200px;
            background-color:lightgreen;
        }
        .DivRow
        {
           clear:left;
           width:400px;
        }
        .DivCellLabel{
            float:left;
            width:200px;
            background-color:powderblue;
        }
        .DivCellContent{
            float:left;
            width:200px;
            background-color:lightgreen;
        }
    </style>
    <div>
        <table cellpadding="0" cellspacing="0">
                @foreach (Product p in Model)
                {
                    <tr>
                        <td class="TableLabel" width="200px">@p.ProductCode</td>
                        <td class="TableContent" width="200px">@p.ProductName</td>
                    </tr>
                }
        </table>
    </div>
    <hr />
    <div>
        @foreach(Product p in Model)
        {
            <div class="DivRow">
                <div class="DivCellLabel">@p.ProductCode</div>
                <div class="DivCellContent">@p.ProductName</div>
            </div>
        }
    </div>
</body>
</html>