【问题标题】:How to adjust navigation tool bar width for iphone and ipad?如何调整 iphone 和 ipad 的导航工具栏宽度?
【发布时间】:2016-06-12 15:09:24
【问题描述】:

我正在为 iphone 和 ipad 开发一个网页。我创建了一个导航工具栏,在 ipad 上看起来不错,但在 iphone 上只显示了两个超链接!谁能告诉我如何缩小导航工具栏,以便所有超链接都显示在 iphone 6 屏幕上?(我希望所有导航栏超链接都显示在 iphone 和 ipad 上)。提前致谢?

  ul#navigation {
    height: 70px;
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #ccc;
    border-width: 1px 0;
    text-align: center;
    font-size: 22px;
    font-family: 'Cham-WebFont', Arial, sans-serif;
    background-color: #FFF;
    position: fixed;
    /* new */
    bottom: 0;
    /* new */
    width: 100%;
    /* new */
  }
  ul#navigation li {
    display: inline;
    margin-right: .75em;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  ul#navigation li.last {
    margin-right: 0;
  }
  #MenuContainer {
    text-align: center;
    margin: 50px auto;
  }
  #MenuContainer a {
    margin: 0px 20px;
    display: inline-block;
    text-decoration: none;
    color: black;
  }
<meta name="apple-mobile-web-app-capable" content="yes">
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
<link href="./TEST.css" rel="stylesheet" type="text/css">
<div id="MenuContainer">
  <ul id="navigation">

    <li class="x">
      <a title="1" href="./test.php?a">
        <img id="Button1" src="./1.png" alt="" width="42" height="42" border="0">
        <div class="caption">First</div>
      </a>
    </li>
    <li class="x">
      <a title="2" href="./test.php" onclick="location.href=this.href+'?b&id='+currentID;return false;">
        <img id="Button2" src="./2.png" alt="" width="42" height="42" border="0">
        <div class="caption">Second</div>
      </a>
    </li>
    <li class="x">
      <a title="3" href="./test.php?c">
        <img id="Button3" src="./2.png" alt="" width="42" height="42" border="0">
        <div class="caption">Third</div>
      </a>
    </li>
    <li class="x">
      <a title="4" href="./test.php?d">
        <img id="Button4" src="./3.png" alt="" width="42" height="42" border="0">
        <div class="caption">Fourth</div>
      </a>
    </li>
    <li class="x">
      <a title="5" href="./test.php?e">
        <img id="Button5" src="./4.png" alt="" width="42" height="42" border="0">
        <div class="caption">Fifth</div>
      </a>
    </li>
</ul>
</div>

【问题讨论】:

  • 您可以简单地为每个li 使用百分比宽度,并将它们作为浮动块或内联块。我不建议这样做,因为小屏幕设备中的一行中的 5 个链接可能不是最用户友好的。你的决定。

标签: php html css iphone ipad


【解决方案1】:

您可以将height:70px; 替换为max-height: 100%; min-height:70px;

见片段:

ul#navigation {
    max-height: 100%;
    min-height:70px;
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #ccc;
    border-width: 1px 0;
    text-align: center;
    font-size: 22px;
    font-family: 'Cham-WebFont', Arial, sans-serif;
    background-color: #FFF;
    position: fixed;
    /* new */
    bottom: 0;
    /* new */
    width: 100%;
    /* new */
  }
  ul#navigation li {
    display: inline;
    margin-right: .75em;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  ul#navigation li.last {
    margin-right: 0;
  }
  #MenuContainer {
    text-align: center;
    margin: 50px auto;
  }
  #MenuContainer a {
    margin: 0px 20px;
    display: inline-block;
    text-decoration: none;
    color: black;
  }
<div id="MenuContainer">
  <ul id="navigation">
    <li class="x">
      <a title="1" href="./test.php?a">
        <img id="Button1" src="./1.png" alt="" width="42" height="42" border="0">
        <div class="caption">First</div>
      </a>
    </li>
    <li class="x">
      <a title="2" href="./test.php" onclick="location.href=this.href+'?b&id='+currentID;return false;">
        <img id="Button2" src="./2.png" alt="" width="42" height="42" border="0">
        <div class="caption">Second</div>
      </a>
    </li>
    <li class="x">
      <a title="3" href="./test.php?c">
        <img id="Button3" src="./2.png" alt="" width="42" height="42" border="0">
        <div class="caption">Third</div>
      </a>
    </li>
    <li class="x">
      <a title="4" href="./test.php?d">
        <img id="Button4" src="./3.png" alt="" width="42" height="42" border="0">
        <div class="caption">Fourth</div>
      </a>
    </li>
    <li class="x">
      <a title="5" href="./test.php?e">
        <img id="Button5" src="./4.png" alt="" width="42" height="42" border="0">
        <div class="caption">Fifth</div>
      </a>
    </li>
</ul>

【讨论】:

  • 感谢您的回复。我在 ipad 上对其进行了测试,它显示了 5 个超链接中的 4 个,而在 iphone 上,它在第一行显示了 3 个超链接,而在第二行仅显示了另外两个超链接的一部分?是否可以在两个设备的一行中显示所有 5 个超链接或一行显示 3 个,第二行显示 2 个?
  • @user1788736 您可以随时查看下拉列表@@css-tricks.com/convert-menu-to-dropdown 或按设备宽度等比例缩小 li,但如果太小可能会导致意外按下错误链接的问题。
  • 感谢您建议下拉方法,稍后我将测试该选项。我更改了 css 上的文本字体,并获得了更多空间。我怎样才能减少不同超链接之间的差距?
  • @user1788736 只是减少 #MenuContainer a 的边距
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-20
  • 2016-07-15
相关资源
最近更新 更多