为什么我的导航栏在移动设备上缩放页面?
Why is my navbar scaling the page on mobile?
我的网站在 android 移动设备的 chrome 浏览器上存在缩放问题。这不会发生在移动版 Firefox 或任何桌面浏览器中。当导航栏被选中并下拉时,它会缩放网页。请注意,根据选择的下拉列表,页面的缩放比例不同。导航栏似乎有不可见的内容,当下拉行为被激活时,这些内容会破坏框架。
我已经拼接了4个问题的截图。
非常感谢您提供修复或解决方法方面的帮助。
#NavigationBarList{
list-style-type:none;
padding:0;
}
li{
font-size:130%;
}
nav a{
display:block;
}
/* This customizes the presentation of the list elements (menu items) in the navbar. */
nav li{
display:block;
font-weight:bold;
font-size:200%;
color:#7F1717;
background-color:#9E939E;
width:25%;
text-align:center;
text-decoration:none;
text-transform:uppercase;
z-index:11;
-moz-box-shadow: inset 0 0 1px #000000;
-webkit-box-shadow: inset 0 0 1px #000000;
box-shadow: inset 0 0 1px #000000;
}
nav ul{
width:100%;
}
/* Hide the sub menu items. */
nav ul ul {
display:none;
}
nav ul ul ul {
display:none
}
/* When hovered over, the CSS menu will drop down. */
nav li:hover > ul {
text-align:center;
font-size:40%;
display:block;
}
/* Don't underline links in the list elements (menu items). */
ul a {
text-decoration:none;
color:#7F1717;
}
/* Change the background color of hovered list elements. This was both active and hover... */
nav li:hover{
background-color:#625C62;
}
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:100%
}
nav ul ul ul{
position: absolute;
width:400%;
left:100%;
top:0;
}
#totheleft{
left:-100%;
}
nav ul ul ul li{
text-align:center;
font-size:250%;
}
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
}
<nav>
<ul id="NavigationBarList">
<li style="float:left;">Events
<ul>
<li><a href="tournaments.html">Tournaments</a></li>
<li><a href="kids_hour.html">Kid's Hour</a></li>
<li><a href="calendar.html">Local Calendar</a></li>
</ul>
</li>
<li style="float:left;">Programs
<ul>
<li><a href="summer_camps.html">Summer Camps</a></li>
<li>In Schools
<ul>
<li><a href="schools.html">After School</a></li>
<li><a href="school_registration.html">Registration</a></li>
</ul>
</li>
<li><a href="instructors.html">Local Instructors</a></li>
</ul>
</li>
<li style="float:left;">Content
<ul>
<li><a href="posts.html">Posts</a></li>
<li><a href="games.html">Games</a>
</ul>
</li>
</li>
<li style="float:left;">Connect
<ul>
<li><a href="contact.html">Contact Us</a></li>
<li>Resources
<ul id="totheleft">
<li><a href="links.html">Chess</a></li>
<li><a href="go_links.html">Go</a></li>
<li><a href="xiangqi_links.html">Xiangqi</a></li>
<li><a href="shogi_links.html">Shogi</a></li>
<li><a href="backgammon_links.html">Backgammon</a></li>
</ul>
</li>
<li><a href="about us.html">About Us</a></li>
</ul>
</li>
</ul>
</nav>
我访问了您的网站并快速检查了它...我注意到您正在使用绝对定位将您的内容定位在页面的中心。我认为这就是导致您出现问题的原因。
我会查找有关如何创建重复背景图像并使用它的教程,而不是尝试使用没有重复的图像。然后你可以将你的内容居中 margin: 0 auto.
我知道这不是一个明确的答案,但我希望它能将你推向正确的方向。
将此添加到您所有页面的 head
部分。
<meta name="viewport" content="user-scalable=0">
Without a viewport, mobile devices will render the page at a typical desktop screen width, scaled to fit the screen.
因此,当您在移动设备上访问网页时,视图实际上会缩小以适合您的所有内容。当您触摸导航栏时,浏览器也会尝试放大。设置 user-scalable=0
可以防止这种情况发生。
缺点是您的用户将无法再在移动设备上缩放网站,但唯一的选择是重写您的网站以使用流畅的布局。
您的 <ul>
包含下拉项的宽度为 100%。这意味着宽度将是第一个相对定位的父级(在本例中为 <body>
)的 100%。这会导致 x 轴溢出。
您可以将 <ul>
的宽度设为 25%,将 <li>
的宽度设为 100%,而不是现在 <li>
的宽度设为 25%。
给你
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:25%;
}
和
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
width:100%;
}
我想出的解决方法是在我的叠加层上设置 overflow-x:hidden。我之前在 body 上试过这个,但是在 Android 上 overflow-x 在 body 上不起作用;它必须为容器设置。大概有一个相关的原因导致此问题仅在 Android 上出现。此解决方法非常有效。
我的网站在 android 移动设备的 chrome 浏览器上存在缩放问题。这不会发生在移动版 Firefox 或任何桌面浏览器中。当导航栏被选中并下拉时,它会缩放网页。请注意,根据选择的下拉列表,页面的缩放比例不同。导航栏似乎有不可见的内容,当下拉行为被激活时,这些内容会破坏框架。
我已经拼接了4个问题的截图。
非常感谢您提供修复或解决方法方面的帮助。
#NavigationBarList{
list-style-type:none;
padding:0;
}
li{
font-size:130%;
}
nav a{
display:block;
}
/* This customizes the presentation of the list elements (menu items) in the navbar. */
nav li{
display:block;
font-weight:bold;
font-size:200%;
color:#7F1717;
background-color:#9E939E;
width:25%;
text-align:center;
text-decoration:none;
text-transform:uppercase;
z-index:11;
-moz-box-shadow: inset 0 0 1px #000000;
-webkit-box-shadow: inset 0 0 1px #000000;
box-shadow: inset 0 0 1px #000000;
}
nav ul{
width:100%;
}
/* Hide the sub menu items. */
nav ul ul {
display:none;
}
nav ul ul ul {
display:none
}
/* When hovered over, the CSS menu will drop down. */
nav li:hover > ul {
text-align:center;
font-size:40%;
display:block;
}
/* Don't underline links in the list elements (menu items). */
ul a {
text-decoration:none;
color:#7F1717;
}
/* Change the background color of hovered list elements. This was both active and hover... */
nav li:hover{
background-color:#625C62;
}
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:100%
}
nav ul ul ul{
position: absolute;
width:400%;
left:100%;
top:0;
}
#totheleft{
left:-100%;
}
nav ul ul ul li{
text-align:center;
font-size:250%;
}
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
}
<nav>
<ul id="NavigationBarList">
<li style="float:left;">Events
<ul>
<li><a href="tournaments.html">Tournaments</a></li>
<li><a href="kids_hour.html">Kid's Hour</a></li>
<li><a href="calendar.html">Local Calendar</a></li>
</ul>
</li>
<li style="float:left;">Programs
<ul>
<li><a href="summer_camps.html">Summer Camps</a></li>
<li>In Schools
<ul>
<li><a href="schools.html">After School</a></li>
<li><a href="school_registration.html">Registration</a></li>
</ul>
</li>
<li><a href="instructors.html">Local Instructors</a></li>
</ul>
</li>
<li style="float:left;">Content
<ul>
<li><a href="posts.html">Posts</a></li>
<li><a href="games.html">Games</a>
</ul>
</li>
</li>
<li style="float:left;">Connect
<ul>
<li><a href="contact.html">Contact Us</a></li>
<li>Resources
<ul id="totheleft">
<li><a href="links.html">Chess</a></li>
<li><a href="go_links.html">Go</a></li>
<li><a href="xiangqi_links.html">Xiangqi</a></li>
<li><a href="shogi_links.html">Shogi</a></li>
<li><a href="backgammon_links.html">Backgammon</a></li>
</ul>
</li>
<li><a href="about us.html">About Us</a></li>
</ul>
</li>
</ul>
</nav>
我访问了您的网站并快速检查了它...我注意到您正在使用绝对定位将您的内容定位在页面的中心。我认为这就是导致您出现问题的原因。
我会查找有关如何创建重复背景图像并使用它的教程,而不是尝试使用没有重复的图像。然后你可以将你的内容居中 margin: 0 auto.
我知道这不是一个明确的答案,但我希望它能将你推向正确的方向。
将此添加到您所有页面的 head
部分。
<meta name="viewport" content="user-scalable=0">
Without a viewport, mobile devices will render the page at a typical desktop screen width, scaled to fit the screen.
因此,当您在移动设备上访问网页时,视图实际上会缩小以适合您的所有内容。当您触摸导航栏时,浏览器也会尝试放大。设置 user-scalable=0
可以防止这种情况发生。
缺点是您的用户将无法再在移动设备上缩放网站,但唯一的选择是重写您的网站以使用流畅的布局。
您的 <ul>
包含下拉项的宽度为 100%。这意味着宽度将是第一个相对定位的父级(在本例中为 <body>
)的 100%。这会导致 x 轴溢出。
您可以将 <ul>
的宽度设为 25%,将 <li>
的宽度设为 100%,而不是现在 <li>
的宽度设为 25%。
给你
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:25%;
}
和
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
width:100%;
}
我想出的解决方法是在我的叠加层上设置 overflow-x:hidden。我之前在 body 上试过这个,但是在 Android 上 overflow-x 在 body 上不起作用;它必须为容器设置。大概有一个相关的原因导致此问题仅在 Android 上出现。此解决方法非常有效。