Bootstrap 4移动网站的行为类似于台式机 [英] Bootstrap 4 mobile site acting like desktop

查看:45
本文介绍了Bootstrap 4移动网站的行为类似于台式机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用引导程序4的网站.在我的计算机上进行测试时,一切看起来都不错,并且可以适当调整屏幕分辨率的大小.像这样:

I have a website that's using bootstrap 4. When testing on my computer everything looks okay and properly resized for the screen resolution. Like so:

但是当我在手机上加载同一页面时:

But then when I load the same page on my mobile:

它在桌面屏幕上使用网格布局.有人知道这是为什么吗?有人告诉我这将有助于支持移动设备<meta name="viewport" contain="width=device-width, initial-scale=1.0">,因此已将meta标签添加到标头中.我不知道还有什么可能设置错误!

It's using the grid layout for a desktop screen. Does anybody know why this is? I've added this meta tag into the header as I was told this will help support mobile devices <meta name="viewport" contain="width=device-width, initial-scale=1.0">. I don't know what else could be setup wrong!

我的<head>代码:

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">

    <link rel="stylesheet" href="/css/master.css" type="text/css">
    @yield('css_includes')

    <meta name="viewport" contain="width=device-width, initial-scale=1.0">
</head>
<body>
    @yield('navbar')

    <div class="container-fluid h-100">
        @yield('content')
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    @yield('page_scripts')
    @stack('extra_scripts')
</body>
</html>

导航栏的代码:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/">Order Happy</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar_content" aria-controls="navbar_content" aria-expanded="false" aria-label="Toggle Navigation">
    <span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbar_content">
    <ul class="navbar-nav mr-auto">
        <li class="nav-item {{ request()->is($business->business_slug) ? 'active' : '' }}">
            <a class="nav-link" href="/{{ $business->business_slug }}">{{ $business->name }}</a>
        </li>
        <li class="nav-item {{ request()->is($business->business_slug . "/basket") ? 'active' : '' }}">
            <a class="nav-link" href="/{{ $business->business_slug }}/basket">Basket <span class="badge badge-light">{{ $basket_quantity }}</span></a>
        </li>
    </ul>
</div>
</nav>

推荐答案

引导程序强烈建议您在使用引导程序时将这3个meta标记包含在<head>标记内.

Bootstrap strongly suggests to have these 3 meta tags inside <head> tag when you are using bootstrap.

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

尝试添加所有这3个标签.另外,请在您的移动浏览器中检查是否启用了显示桌面网站视图"的选项.

Try adding all these 3 tags. And also, check in your mobile browser if the option to display 'desktop website view' is enabled.

这篇关于Bootstrap 4移动网站的行为类似于台式机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆