【问题标题】:Cuts the header of a web page when viewing through a smartphone browser (ASP.net Core MVC 3.1)通过智能手机浏览器查看网页时剪切网页标题 (ASP.net Core MVC 3.1)
【发布时间】:2020-05-31 08:05:02
【问题描述】:

在 ASP.net Core MVC 3.1 堆栈上创建了一个 Web 应用程序。从手机以 360 x 740 的分辨率查看时,有些网页被裁剪(在标题和表格中)。从平板电脑或 PC 上查看时,一切都很好。我试图同时更改 _Layout 文件和 View 文件。但没有积极作用。

It's ok here:

When viewing from a mobile cut in "Head" and below:

_Layout.cshtml:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>   
   
    <link rel="stylesheet" asp-href-include="lib/bootstrap/dist/css/*.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/fontawesome.min.css" />
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="~/js/a076d05399.js"></script>
</head>

<body>
    <!-- Sidebar -->
    <div class="w3-sidebar w3-bar-block w3-collapse w3-card w3-animate-left w3-indigo" style="width:200px;" id="mySidebar">
        <button class="w3-bar-item w3-button w3-large w3-hide-large w3-hover-white" onclick="w3_close()">&times;</button>

        <center><h1>HOMIE</h1></center>
        <hr>

        <a asp-area="" asp-controller="Home" asp-action="Index" class="w3-bar-item w3-button w3-hover-white">
            <i class="fa fa-fw fa-lg fa-home"></i>&nbsp; Домой
        </a>

        <button class="w3-button w3-block w3-left-align w3-hover-white" onclick="myAccSeriesFunc()">
            <i class="fa fa-film fa-fw fa-lg"></i>&nbsp; Сериалы <i class="fa fa-caret-down"></i>
        </button>
        <div id="seriesAcc" class="w3-hide w3-light-gray w3-card">
            <a asp-area="Series" asp-controller="Home" asp-action="Index" class="w3-bar-item w3-button w3-hover-white">
                <i class="fa fa-video fa-fw" aria-hidden="true"></i>&nbsp; Просмотр
            </a>

            <a asp-area="Series" asp-controller="Home" asp-action="ArchMovies" class="w3-bar-item w3-button w3-hover-white">
                <i class="fa fa-fast-backward fa-fw" aria-hidden="true"></i>&nbsp; Архив
            </a>
        </div>

        <a asp-area="Cigars" asp-controller="Home" asp-action="Index" class="w3-bar-item w3-button w3-hover-white">
            <i class="fas fa-joint fa-lg"></i>&nbsp; Сигары
        </a>        

        <a method="post" asp-area="Identity" asp-controller="Home" asp-action="Index" class="w3-bar-item w3-button w3-hover-white"><i class="fas fa-sign-in-alt fa-lg"></i>&nbsp; Выход</a>
    </div>

    <!-- Page Content -->
    <div class="w3-main" style="margin-left:200px">

        <div class="w3-indigo">
            <button class="w3-button w3-xlarge w3-hide-large" onclick="w3_open()">&#9776;</button>
            <div class="w3-container w3-indigo">
                <h1>@ViewBag.HeaderTitle</h1>
            </div>
        </div>
        <p></p>

        <div class="w3-container">
            @RenderBody()
        </div>

        <script>    

            function myAccSeriesFunc() {
                var x = document.getElementById("seriesAcc");
                if (x.className.indexOf("w3-show") == -1) {
                x.className += " w3-show";
                x.previousElementSibling.className += " w3-white";
                } else {
                x.className = x.className.replace(" w3-show", "");
                x.previousElementSibling.className =
                    x.previousElementSibling.className.replace(" w3-white", "");
                }                
            }

            function myAccAdminFunc() {
                var y = document.getElementById("adminAcc");
                if (y.className.indexOf("w3-show") == -1) {
                y.className += " w3-show";
                y.previousElementSibling.className += " w3-white";
                } else {
                y.className = y.className.replace(" w3-show", "");
                y.previousElementSibling.className =
                    y.previousElementSibling.className.replace(" w3-white", "");
                }
            }

            function w3_open() {
                document.getElementById("mySidebar").style.display = "block";

            }

            function w3_close() {
                document.getElementById("mySidebar").style.display = "none";
            }
        </script>
    </div>

   

</body>
</html>

Index.cshtml:

@using Homie.Models
@model IndexViewModel

@addTagHelper *, Homie

@{
    ViewBag.Title = "Список выкуренных сигар";
    ViewBag.HeaderTitle = "Сигары - - - - [ История ]";
}

<style>
    .table-striped > tbody > tr:nth-child(odd) > td,
    .table-striped > tbody > tr:nth-child(odd) > th {
        background-color: sandybrown;
    }    
</style>

<a asp-action="Create" asp-controller="Home" asp-area="Cigars"
   class="btn btn-primary"
   role="button">Добавить</a>
<p></p>

<form method="get">
    <div class="form-inline">
        <label>Название: </label>
        <input name="name" value="@Model.FilterViewModel.SelectedName" class="form-control" />

        <label>Формат: </label>        
        <select name="format" asp-items="Model.FilterViewModel.Formats" class="form-control"></select>        

        <input type="submit" value="Фильтр" class="btn btn-outline-dark" />
    </div>
</form>
<p></p>

<div>
    <label>Количество сигар: @Model.PageViewModel.CountPages</label>
</div>

<table class="table table-bordered table-striped table-sm">
    <tr>
        <th>
            <a asp-action="Index"
               asp-route-sortOrder="@(Model.SortViewModel.NameSort)"
               asp-route-name="@(Model.FilterViewModel.SelectedName)"
               asp-route-format="@(Model.FilterViewModel.SelectedFormat)">Название</a>
        </th>
        <th>Страна</th>
        <th>Цена</th>
        <th>Рейтинг</th>
        <th>
            <a asp-action="Index" asp-route-sortOrder="@(Model.SortViewModel.FormatSort)"
               asp-route-name="@(Model.FilterViewModel.SelectedName)"
               asp-route-format="@(Model.FilterViewModel.SelectedFormat)">Формат</a>
        </th>
        <th></th>
    </tr>
    @foreach (var p in Model.Cigars)
    {
        <tr>
            <td>@p.Name</td>
            <td>@p.Country</td>
            <td>@p.Price</td>
            <td>@p.Rating</td>
            <td>@p.Shape</td>
            <td>

                <a asp-action="Edit" asp-controller="Home" asp-route-id="@p.Id" class="btn btn-success"
                   role="button">Изменить</a>
                <a asp-action="Delete" asp-controller="Home" asp-route-id="@p.Id" class="btn btn-danger"
                   role="button">Удалить</a>
            </td>
        </tr>

    }
</table>
<p></p>
<page-link page-model="Model.PageViewModel" page-action="Index"
           page-url-name="@(Model.FilterViewModel.SelectedName)"
           page-url-company="@(Model.FilterViewModel.SelectedFormat)"
           page-url-sortorder="@(Model.SortViewModel.Current)"></page-link>

【问题讨论】:

    标签: html css razor asp.net-core-mvc


    【解决方案1】:

    &lt;table&gt; 的本质是它们是固定宽度的。你需要让你的表格在超过父宽度时有一个滚动条,或者想办法在移动设备上折叠列(DataTables.js 有一些开箱即用的好工具)。下面是让表格滚动的例子:

    https://jsfiddle.net/Lv3sw20g/6/

    【讨论】:

    • 也就是说,如果我在桌子上做一个滚动条,上边框会被拉伸吗?我只是不太明白。毕竟,表格以全宽正确显示。问题不在最前面?
    • 不。据我所知,该表格正在推动整个页面的宽度。
    • 好的。我会制作滚动条,我希望这能解决问题。谢谢!!
    猜你喜欢
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2012-12-28
    • 1970-01-01
    相关资源
    最近更新 更多