Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

css - Trying and failing to render two tables side by side with HTML and Bootstrap

I'm trying to render some simple HTML/Bootstrap tables side by side but getting stuck at this even after trying the previous solutions offered from on here. I'm sure it's something simple but I'm new to this, so any help would be appreciated.

I have two lists in my model, of equal size, that I would like to display beside each other. The correct data is being displayed, but I simply cannot get them to render alongside each other:

//Layout

@using RazorLight

<html>
<head>
    <title>Daily Email</title>
    <link type="text/css" href="bootstrap.css" />
</head>
<body>
    <div id="body">
        @RenderBody()
    </div>
</body>
</html>

//DailyReportingEmail

@using Solution.Shared.Models
@inherits RazorLight.TemplatePage<Report>
@model Report
@{
    Layout = "_Layout.cshtml";
}

    <div>

    <p>
        <strong>
            This is an automated email.
            Do not reply to this email.
        </strong>
    </p>

    <p class="lead">
        The Data is sourced from Report.
    </p>

    <h1>Daily Totals: </h1>

    @{
        await IncludeAsync("Includes/DailyTotalsTable.cshtml", Model);
    }

</div>

//DailyTotalsTable

@using Solution.Shared.Models
@inherits RazorLight.TemplatePage<Report>
@model Report

<div class="col-6">
<table class="table">
    <thead>
        <tr>
            <th>Category</th>
            <th>Previous</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var record in Model.PreviousTotals)
        {
            <tr>
                <td>@record.Category</td>
                <td>@record.Value</td>
            </tr>
        }
    </tbody>
</table>
</div>
<div class="col-6">
    <table class="table">
        <thead>
            <tr>
                <th>Current</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var record in Model.CurrentTotals)
            {
                <tr>
                    <td>@record.Value</td>
                </tr>
            }
        </tbody>
    </table>
</div>
question from:https://stackoverflow.com/questions/65843988/trying-and-failing-to-render-two-tables-side-by-side-with-html-and-bootstrap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have not added bootstrap class row. Wrap your code around div with class="row"

<div class="row">
<div class="col-6">
<table class="table">
    <thead>
        <tr>
            <th>Category</th>
            <th>Previous</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var record in Model.PreviousTotals)
        {
            <tr>
                <td>@record.Category</td>
                <td>@record.Value</td>
            </tr>
        }
    </tbody>
</table>
</div>
<div class="col-6">
    <table class="table">
        <thead>
            <tr>
                <th>Current</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var record in Model.CurrentTotals)
            {
                <tr>
                    <td>@record.Value</td>
                </tr>
            }
        </tbody>
    </table>
</div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...