【问题标题】:Bootstrap Navbar will not collapse on smart phoneBootstrap Navbar 不会在智能手机上折叠
【发布时间】:2016-08-14 05:45:25
【问题描述】:

看来我把所有东西都放在了正确的地方。

在头脑中。没有视口元标记(我试过但没有运气)

<title>My Title for Webpage</title>

<link href="css/bootstrap.min.css" rel="stylesheet" />

结束标记的正上方

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>

这里是导航栏 html

<div class="navbar navbar-default navbar-fixed-top" style="border: 1px solid red;
    padding-left: 20px; padding-right: 30px;">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span><span
                class="icon-bar"></span><span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#"><span class="title">Portland Dancing</span></a>
    </div>
    <div class="navbar-collapse collapse" style="max-height: 100%;">
        <ul class="nav navbar-nav navbar-left">
            <li>
                <asp:DropDownList ID="ddlChoose" runat="server" AutoPostBack="true" CssClass="form-control"
                    EnableViewState="false" DataTextField="DanceStyle" DataValueField="DanceStyle">
                </asp:DropDownList>
            </li>
            <li>
                <asp:DropDownList ID="ddlChooseDateRanges" runat="Server" AutoPostBack="true" CssClass="form-control"
                    OnSelectedIndexChanged="DateRangePullDownHandler" EnableViewState="false">
                    <asp:ListItem Value="All Days">All Days</asp:ListItem>
                    <asp:ListItem Value="Christmas">Christmas</asp:ListItem>
                    <asp:ListItem Value="New Years Eve">New Year's Eve</asp:ListItem>
                    <asp:ListItem Value="Today">Today</asp:ListItem>
                    <asp:ListItem Value="Tomorrow">Tomorrow</asp:ListItem>
                    <asp:ListItem Value="Today Tomorrow">Today Tomorrow</asp:ListItem>
                    <asp:ListItem Value="This Weekend">This Weekend</asp:ListItem>
                    <asp:ListItem Value="Next Weekend">Next Weekend</asp:ListItem>
                    <asp:ListItem Value="This Week">This Week</asp:ListItem>
                    <asp:ListItem Value="Fridays">Fridays</asp:ListItem>
                    <asp:ListItem Value="Saturdays">Saturdays</asp:ListItem>
                    <asp:ListItem Value="Sundays">Sundays</asp:ListItem>
                    <asp:ListItem Value="Mondays">Mondays</asp:ListItem>
                    <asp:ListItem Value="Tuesdays">Tuesdays</asp:ListItem>
                    <asp:ListItem Value="Wednesdays">Wednesdays</asp:ListItem>
                    <asp:ListItem Value="Thursdays">Thursdays</asp:ListItem>
                    <asp:ListItem Value="Before 1pm">Before 1pm</asp:ListItem>
                    <asp:ListItem Value="Before 3pm">Before 3pm</asp:ListItem>
                    <asp:ListItem Value="Before 6pm">Before 6pm</asp:ListItem>
                    <asp:ListItem Value="Before 9pm">Before 9pm</asp:ListItem>
                </asp:DropDownList>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li>
                <asp:LinkButton ID="lnkPrint" Style="margin-bottom: 5px; padding: 6px 0px;" CssClass="form-control"
                    CausesValidation="False" BackColor="#f6f2dc" ForeColor="Black" runat="server"
                    EnableViewState="false" title="Make your choices with the checkboxes and then Print them">Print</asp:LinkButton>
            </li>
            <li>
                <asp:LinkButton ID="lnkEmail" Style="margin-bottom: 5px; padding: 6px 0px;" CssClass="form-control"
                    runat="server" CausesValidation="False" BackColor="#f6f2dc" ForeColor="Black"
                    EnableViewState="false" title="Make your choices with the checkboxes and then Email them">
            Email
                </asp:LinkButton></li>
            <li>
                <asp:DropDownList ID="ddlAgesPrice" runat="Server" AutoPostBack="true" OnSelectedIndexChanged="AgesPricePulldownHandler"
                    CssClass="form-control" EnableViewState="false" Style="text-align: center;">
                    <asp:ListItem Value="Ages, Price" Enabled="false">(Ages, Price)</asp:ListItem>
                    <asp:ListItem Value="All, All">All, All</asp:ListItem>
                    <asp:ListItem Value="All, Free">All, Free</asp:ListItem>
                    <asp:ListItem Value="Under 21, All">Under 21, All</asp:ListItem>
                    <asp:ListItem Value="Under 21, Free">Under 21, Free</asp:ListItem>
                    <asp:ListItem Value="Over 50, All">Over 50, All</asp:ListItem>
                    <asp:ListItem Value="Over 50, Free">Over 50, Free</asp:ListItem>
                </asp:DropDownList>
            </li>
            <li>
                <asp:CheckBox ID="chkInflate" CssClass="form-control" EnableViewState="True" AutoPostBack="True"
                    BackColor="#f6f2dc" ForeColor="Black" Style="margin-bottom: 5px;" runat="Server"
                    ToolTip="Check/Uncheck the box to have all the names expand with more info on this web page. Or go over and click on an event name to pop up a whole bunch of information.">
                </asp:CheckBox></li>
            <li>
            <a href="emailus.aspx" class="form-control" style="color: black; background-color: #f6f2dc; margin-bottom: 7px; font-size: 14px; padding: 6px 0px;" target="_blank" title="Do you have a dance to list? Problem with a listing? Advice for us? Click here to email us. Classes and workshops are in a different area: Learn Stuff">
                Contact</a>
             </li>
            <li>
            <a href="learn.aspx" target="_blank" class="form-control" style="font-weight: bold;
                margin-bottom: 7px; color: Red; background-color: #f6f2dc; font-size: 14px; padding: 6px 0px;"
                title="You must click here to see the Lessons, Worksops, and Gatherings, Private Lessons.">
                Lessons</a>
            </li>
        </ul>
    </div>
</div>

这是使用 Chrome 开发者工具在 iphone 5 上的样子。这在我的 iphone6plus 上是一样的。它应该被折叠并在右侧显示切换按钮:

这是使用 Chrome 开发者工具的常规浏览器大小(笔记本电脑)。按照设计:

有趣且让我困惑的是,我可以通过在窗口右侧拖动来缩小我的 Chrome 浏览器窗口,并且切换按钮会显示并工作。这有点表明我在做几乎正确的事情。 . .直到我尝试我的 iPhone6plus

我还折叠了我的 li 标签并进行了屏幕打印,以便更好地查看:

【问题讨论】:

  • 尝试设置视口:&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;.
  • 请贴出完整的源代码,用你提供的sn-ps,很难找到问题。
  • @Karin 你是对的!嘿,我之前的视口有问题。当我编辑这个问题时,你回答了它。那个人很快。如果它是一条蛇,它会咬我。然而。 . . .我需要上传它并在我的智能手机上打开它。请将此作为答案,以便我可以接受它,如果它适用于我的手机。谢谢
  • 好吧,在将“元视口”标签放回后,它可以在我的 iphone6plus 上运行。我确实发布了完整的源代码。而且它的屏幕打印也缩小了。所以,我要开始下一个脑筋急转弯了。

标签: jquery css twitter-bootstrap toggle navbar


【解决方案1】:

正如我在评论中提到的,将&lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; 添加到head 部分应该可以解决您的问题。您可以阅读更多关于视口的信息here,但要点是:

width=device-width 部分设置页面的宽度以跟随 设备的屏幕宽度(取决于设备)。

initial-scale=1.0 部分设置页面时的初始缩放级别 由浏览器首先加载。

因此,这让手机知道不会挤压您的网页,并且它的设计考虑了移动缩放:)

【讨论】:

  • 在这漫长的 2 天里,我遇到了所有这些解释。谢谢谷歌和堆栈溢出。我认为它弄乱了我缩小的屏幕的身体部分,这是另一个睡觉时间的故事。一次一小步。谢谢@Karin。 . .. 伙计,让一个旧的 asp.net webforms 网站具有响应性是很困难的。细节决定成败。我想我可以采用样板引导模板的“瘦弱”外观。 Boot Strap 的缩写是。 . . . . .
【解决方案2】:

我猜你想念这个&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;

 
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="navbar navbar-default navbar-fixed-top" style="border: 1px solid red;
    padding-left: 20px; padding-right: 30px;">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span><span
                class="icon-bar"></span><span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#"><span class="title">Portland Dancing</span></a>
    </div>
    <div class="navbar-collapse collapse" style="max-height: 100%;">
        <ul class="nav navbar-nav navbar-left">
            <li>
                <asp:DropDownList ID="ddlChoose" runat="server" AutoPostBack="true" CssClass="form-control"
                    EnableViewState="false" DataTextField="DanceStyle" DataValueField="DanceStyle">
                </asp:DropDownList>
            </li>
            <li>
                <asp:DropDownList ID="ddlChooseDateRanges" runat="Server" AutoPostBack="true" CssClass="form-control"
                    OnSelectedIndexChanged="DateRangePullDownHandler" EnableViewState="false">
                    <asp:ListItem Value="All Days">All Days</asp:ListItem>
                    <asp:ListItem Value="Christmas">Christmas</asp:ListItem>
                    <asp:ListItem Value="New Years Eve">New Year's Eve</asp:ListItem>
                    <asp:ListItem Value="Today">Today</asp:ListItem>
                    <asp:ListItem Value="Tomorrow">Tomorrow</asp:ListItem>
                    <asp:ListItem Value="Today Tomorrow">Today Tomorrow</asp:ListItem>
                    <asp:ListItem Value="This Weekend">This Weekend</asp:ListItem>
                    <asp:ListItem Value="Next Weekend">Next Weekend</asp:ListItem>
                    <asp:ListItem Value="This Week">This Week</asp:ListItem>
                    <asp:ListItem Value="Fridays">Fridays</asp:ListItem>
                    <asp:ListItem Value="Saturdays">Saturdays</asp:ListItem>
                    <asp:ListItem Value="Sundays">Sundays</asp:ListItem>
                    <asp:ListItem Value="Mondays">Mondays</asp:ListItem>
                    <asp:ListItem Value="Tuesdays">Tuesdays</asp:ListItem>
                    <asp:ListItem Value="Wednesdays">Wednesdays</asp:ListItem>
                    <asp:ListItem Value="Thursdays">Thursdays</asp:ListItem>
                    <asp:ListItem Value="Before 1pm">Before 1pm</asp:ListItem>
                    <asp:ListItem Value="Before 3pm">Before 3pm</asp:ListItem>
                    <asp:ListItem Value="Before 6pm">Before 6pm</asp:ListItem>
                    <asp:ListItem Value="Before 9pm">Before 9pm</asp:ListItem>
                </asp:DropDownList>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li>
                <asp:LinkButton ID="lnkPrint" Style="margin-bottom: 5px; padding: 6px 0px;" CssClass="form-control"
                    CausesValidation="False" BackColor="#f6f2dc" ForeColor="Black" runat="server"
                    EnableViewState="false" title="Make your choices with the checkboxes and then Print them">Print</asp:LinkButton>
            </li>
            <li>
                <asp:LinkButton ID="lnkEmail" Style="margin-bottom: 5px; padding: 6px 0px;" CssClass="form-control"
                    runat="server" CausesValidation="False" BackColor="#f6f2dc" ForeColor="Black"
                    EnableViewState="false" title="Make your choices with the checkboxes and then Email them">
            Email
                </asp:LinkButton></li>
            <li>
                <asp:DropDownList ID="ddlAgesPrice" runat="Server" AutoPostBack="true" OnSelectedIndexChanged="AgesPricePulldownHandler"
                    CssClass="form-control" EnableViewState="false" Style="text-align: center;">
                    <asp:ListItem Value="Ages, Price" Enabled="false">(Ages, Price)</asp:ListItem>
                    <asp:ListItem Value="All, All">All, All</asp:ListItem>
                    <asp:ListItem Value="All, Free">All, Free</asp:ListItem>
                    <asp:ListItem Value="Under 21, All">Under 21, All</asp:ListItem>
                    <asp:ListItem Value="Under 21, Free">Under 21, Free</asp:ListItem>
                    <asp:ListItem Value="Over 50, All">Over 50, All</asp:ListItem>
                    <asp:ListItem Value="Over 50, Free">Over 50, Free</asp:ListItem>
                </asp:DropDownList>
            </li>
            <li>
                <asp:CheckBox ID="chkInflate" CssClass="form-control" EnableViewState="True" AutoPostBack="True"
                    BackColor="#f6f2dc" ForeColor="Black" Style="margin-bottom: 5px;" runat="Server"
                    ToolTip="Check/Uncheck the box to have all the names expand with more info on this web page. Or go over and click on an event name to pop up a whole bunch of information.">
                </asp:CheckBox></li>
            <li>
            <a href="emailus.aspx" class="form-control" style="color: black; background-color: #f6f2dc; margin-bottom: 7px; font-size: 14px; padding: 6px 0px;" target="_blank" title="Do you have a dance to list? Problem with a listing? Advice for us? Click here to email us. Classes and workshops are in a different area: Learn Stuff">
                Contact</a>
             </li>
            <li>
            <a href="learn.aspx" target="_blank" class="form-control" style="font-weight: bold;
                margin-bottom: 7px; color: Red; background-color: #f6f2dc; font-size: 14px; padding: 6px 0px;"
                title="You must click here to see the Lessons, Worksops, and Gatherings, Private Lessons.">
                Lessons</a>
            </li>
        </ul>
    </div>
</div>

【讨论】:

  • 来自原帖“在头部。没有视口元标记(我试过但没有运气)”
  • @Head In Cloud,我支持你,因为在我编辑问题以添加关于视口的评论时,你为我回答了这个问题。谢谢你这么快的回复,不要放弃我。
猜你喜欢
  • 2016-05-18
  • 1970-01-01
  • 2014-02-28
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 2019-12-26
  • 2012-06-25
  • 2018-05-23
相关资源
最近更新 更多