简体   繁体   English

在移动设备上调整顶部导航栏的大小时出现问题

[英]Issue when resizing top navigation bar on mobile

I built this very simple site for work and I found an issue related to the top navigation bar when resizing on mobile (please note there is no mobile version of the site, nor will be). 我建立了一个非常简单的工作网站 ,并在移动设备上调整大小时发现了与顶部导航栏相关的问题(请注意,该网站没有移动版本,现在也不会)。

When resizing on mobile screens, the navigation bar remains fixed, while the content can be moved. 在移动屏幕上调整大小时,导航栏保持固定,而内容可以移动。 This means that, while the navigation bar stays stuck at the top left corner and partially blocks the screen, the text moves freely under it. 这意味着,尽管导航栏停留在左上角并部分阻塞了屏幕,但文本在其下方自由移动。 Please refer to the screenshots below: 请参考以下屏幕截图:

Mobile: Example 1 移动设备:示例1

If you check the source code, the top navigation bar is set to fixed. 如果您检查源代码,则顶部导航栏将设置为固定。 If I remove this line, resizing on mobile works fine, but the top margin specified for the content (so that it doesn't overlap with the navigation bar) becomes huge. 如果我删除此行,则在移动设备上调整大小的效果很好,但是为内容指定的上边距(以便与导航栏不重叠)变得很大。

Changing this margin, however, affects the navigation bar when resizing the window on a computer, as you can see below: 但是,更改此页边距会影响在计算机上调整窗口大小时的导航栏,如下所示:

Desktop: Example 1 桌面:示例1

It's been many years since I last worked with html and css, so please excuse me if I'm missing the obvious. 自从我上一次使用html和css以来已经有很多年了,所以如果我错过了显而易见的内容,请原谅。

How can I find a solution to this? 我如何找到解决方案?

This is happening because you given width and max-width 100% to your top class, If you want to fix this in mobile devices you need to write media query 之所以发生这种情况,是因为您给顶级产品提供了100%的宽度和最大宽度,如果您想在移动设备中解决此问题,则需要编写媒体查询


Try below code to your css 尝试下面的代码到你的CSS


@media (max-width: 500px){ 
div.top{
    width: auto;
    max-width: none;
}}

if you want to show navigation in mobile view then use below code. 如果要在移动视图中显示导航,请使用以下代码。


@media (max-width: 500px){ 
div.top{
    position: relative;
}
div.normal{
    margin-top:200px;
}
ul.menu li{
    float: none;
}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM