【问题标题】:Expand image and navigation menu when page overflows页面溢出时展开图像和导航菜单
【发布时间】:2019-04-12 01:34:18
【问题描述】:

我有一个网站,其中 2 页内容在小屏幕中溢出,这意味着您必须水平滚动才能查看所有内容。因此,屏幕顶部的菜单和徽标图像在这两页上被截断。菜单和徽标都由母版页加载。我尝试通过使用媒体查询并分配特定宽度来解决此问题,这确实解决了这两个页面的问题,但它导致所有页面在小屏幕上滚动,因为该修复影响了母版页。我认为这是一个非常基本的问题,但令人惊讶的是我找不到任何解决方案。我想知道是否有人对如何解决这个问题有任何想法。

编辑:从我的母版页和样式文件中发布代码。

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #ffffff;
    max-width: none;
    overflow: scroll;
}

table {
    border-spacing: 0px
}

td {
    padding: 2px;
    margin: 0px;
    border-spacing: 0px
}
/*-----------------------------------------------------------------Header Logo------------------------------------------------------------------------------------------------*/

.responsive {
    width: 100%;
    height: auto;
}

/*------------------------------------------------------------------------ Menu -----------------------------------------------------------------------------------------*/
.navbar {
    width: 100%;
    overflow: hidden;
    background-color: #333;
    font-family: Arial, Helvetica, sans-serif;
    margin-top: 0px;
    padding-top: 0px;
}

    .navbar a {
        float: left;
        font-size: 16px;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

.dropdown {
    float: left;
}

    .dropdown .dropbtn {
        font-size: 16px;
        border: none;
        outline: none;
        color: white;
        padding: 14px 16px;
        background-color: inherit;
        font-family: inherit;
        margin: 0;
    }

    .navbar a:hover, .dropdown:hover .dropbtn {
        background-color: red;
    }

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

    .dropdown-content a {
        float: none;
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        text-align: left;
    }

        .dropdown-content a:hover {
            background-color: #ddd;
        }

.dropdown:hover .dropdown-content {
    display: block;
}


/*-----------------------------------------------------------------Formatting------------------------------------------------------------------------------------------------*/

.
.under2 {
    text-decoration: underline;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #3A4A37;
}

.box_app {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #3A4A37;
    border: 1px solid #C4D0C1;
}

.validator {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #F00000;
}

.validator_mini {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #F00000;
}

.validator_mini2 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #000080;
}

.subtitles {
    font-weight: bold;
    background-color: #093145;
    border-bottom-style: solid;
    border-bottom-color: #3A4A37;
    border-bottom-width: 1px;
    text-align: left;
    color: white;
}

.textbox_padded {
    border: 1px solid #C4D0C1;
    padding: 4px;
    color: #3A4A37;
    font-family: arial, Helvetica, sans-serif;
}

.title_times_new {
    font-family: "Times New Roman", Times, serif;
    font-size: 32px;
    color: #4D6145;
    font-weight: bold;
    font-style: italic;
    text-align: center;
}

.title_times_new2 {
    font-family: "Times New Roman", Times, serif;
    font-size: 16px;
    color: #4D6145;
    font-weight: bold;
    font-style: italic;
}

.contract_list {
    margin-left: auto;
    margin-right: auto;
}


/*-------------------------------------------------------------------New Contract Form----------------------------------------------------------------------*/
#contract table {
    width: 600px;
}

html, body {
    margin: 0;
    padding: 0;
}

.img-responsive {
    display: inline-block;
    max-width: 100%;
    height: auto;
}

.drop {
    left: 0px;
    margin-right: 90px;
}

.flow {
    width: 1200px
}

/*-------------------------------------------------------------------Media queries----------------------------------------------------------------------*/

@media only screen and (max-width: 1280px) {
    .navbar {
        width: 1670px;
        margin-top: 0px;
    }

    .responsive {
        width: 1670px;
    }

    .contract_list {
        margin-right: 0px;
        margin-left: 1%;
    }
}
<html>
<head runat="server">
    <title></title>

    <link href="~/secure/styles.css" type="text/css" rel="stylesheet" runat="server" />
    <link rel="stylesheet" href="~/secure/font-awesome.min.css" runat="server" />
    <link rel="shortcut icon" type="image/ico" href="images/faviocon/favicon.ico" runat="server" />

    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

</head>
<body>
    <form id="form1" runat="server">
        <img src="images/logo2.png" alt="Logo" runat="server" class="responsive" />
        <div class="navbar" runat="server" style="margin-top: 0px; padding-top: 0px;">
            <div class="dropdown">
                <button class="dropbtn" causesvalidation="false">
                    Clinical Arrangements        
                </button>
                <div class="dropdown-content">
                    <a href="/secure/student_ca_arrangement.aspx">Add New Student</a>
                </div>
            </div>

            <div class="dropdown">
                <button class="dropbtn" causesvalidation="false">
                    Contracts 
                </button>
                <div class="dropdown-content">
                    <a href="/secure/ca_contracts/new_contract.aspx">New Contract</a>
                    <a href="/secure/ca_contracts/contract_list.aspx">Contract List</a>
                </div>
            </div>
            <div class="dropdown">
                <button class="dropbtn" causesvalidation="false">
                    Letters 
                </button>
                <div class="dropdown-content">
                    <a href="/secure/letters/begin_letter_list.aspx">Beginning of Term Letter</a>
                    <a href="/secure/letters/end_letters_list.aspx">End of Term Letter</a>
                </div>
            </div>
            <a id="logout" causesvalidation="false" runat="server" onserverclick="logout_Click">Sign Out</a>
        </div>

        <br />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>

    </form>
    <script type="text/javascript" src="https://cdn.ywxi.net/js/1.js" async></script>
</body>
</html>

【问题讨论】:

  • 如果问题中没有 CSS 或标记,您将不会得到非常有用的答案。
  • @IrishChieftain 完成,感谢您的建议。

标签: javascript css asp.net html


【解决方案1】:

您可以使用

禁用水平滚动
overflow-x:hidden;

在你的 CSS 中

【讨论】:

  • 我其实想要水平滚动条。这 2 页的表格显示了很多导致溢出的列和数据。不过感谢您的提示。
  • 其实我想我会在所有不需要的页面上禁用滚动。这不是最佳解决方案,因为随着网站的增长,我必须将其添加到每个新页面,但现在它可以工作。谢谢。
  • 是的,它不是最理想的,您可以尝试在宽度上设置百分比值/视口值而不是固定像素值,还可以在 chrome 开发工具中检查您网站的父元素,看看是否您还需要在父元素上设置百分比值
【解决方案2】:

您似乎在手动滚动自己的响应式媒体查询?我建议使用 Bootstrap v3 - 你可以使用包管理器来设置整个事情。

在您的媒体查询中,您使用像素将固定宽度设置为 1670 像素。在 RWD 中,从不使用固定的宽度单位;它总是以百分比完成。您可以使用 Bootstrap 来避免这些问题,因为所有繁重的工作都已经为您完成了。

对于您的具体问题,您应该针对不同的屏幕分辨率使用不同的媒体屏幕:

https://getbootstrap.com/docs/3.3/css/#grid-media-queries

【讨论】:

  • 我认为没有必要使用 Bootstrap,因为该网站不需要进行移动优化。我使用固定宽度只是为了将其与那些页面上溢出的表格对齐,因为无论屏幕分辨率如何,表格宽度都不会改变。媒体查询是否会根据页面是否溢出来调整页面?
  • 我在从未在移动设备上使用过的网站上使用 Bootstrap。无论哪种方式,它都让事情变得更容易管理,因为您可能会从不同的屏幕尺寸访问它。
  • 没有。媒体查询和浏览器根据视口大小确定布局。在我看来,你的补救措施比疾病更糟糕。我会回到从头开始并在所有东西周围设置一个容器;-)
猜你喜欢
  • 2017-11-11
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-30
  • 2015-12-13
  • 2016-01-11
相关资源
最近更新 更多