问题
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:
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!
My <head> code:
<!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>
The code for the navbar:
<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>
回答1:
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">
Try adding all these 3 tags. And also, check in your mobile browser if the option to display 'desktop website view' is enabled.
来源:https://stackoverflow.com/questions/49844216/bootstrap-4-mobile-site-acting-like-desktop