Bootstrap 3表响应不起作用

时间:2014-08-06 02:28:59

标签: css responsive-design twitter-bootstrap-3

我正在测试手机中的本地网站(Lumia 920),Bootstrap 3网站显示正常,但是当我访问我的本地网站时,我的桌子看起来没有响应。 我甚至尝试使用Bootstrap页面的示例代码。

这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <!-- Latest compiled and minified JavaScript -->
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body data-twttr-rendered="true">
<div class="container">
    <div class="row">
        <div class="col-md-9">
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th></th>
                        <th>
                            Extra small devices
                            <small>Phones (&lt;768px)</small>
                        </th>
                        <th>
                            Small devices
                            <small>Tablets (≥768px)</small>
                        </th>
                        <th>
                            Medium devices
                            <small>Desktops (≥992px)</small>
                        </th>
                        <th>
                            Large devices
                            <small>Desktops (≥1200px)</small>
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <th class="text-nowrap">Grid behavior</th>
                        <td>Horizontal at all times</td>
                        <td colspan="3">Collapsed to start, horizontal above breakpoints</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Container width</th>
                        <td>None (auto)</td>
                        <td>750px</td>
                        <td>970px</td>
                        <td>1170px</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Class prefix</th>
                        <td><code>.col-xs-</code></td>
                        <td><code>.col-sm-</code></td>
                        <td><code>.col-md-</code></td>
                        <td><code>.col-lg-</code></td>
                    </tr>
                    <tr>
                        <th class="text-nowrap"># of columns</th>
                        <td colspan="4">12</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Column width</th>
                        <td class="text-muted">Auto</td>
                        <td>~62px</td>
                        <td>~81px</td>
                        <td>~97px</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Gutter width</th>
                        <td colspan="4">30px (15px on each side of a column)</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Nestable</th>
                        <td colspan="4">Yes</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Offsets</th>
                        <td colspan="4">Yes</td>
                    </tr>
                    <tr>
                        <th class="text-nowrap">Column ordering</th>
                        <td colspan="4">Yes</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="col-md-3">
            asd
        </div>
    </div>
</div>
</body>
</html>

我做错了什么? 谢谢。

1 个答案:

答案 0 :(得分:2)

由于WP8上的IE10在处理<meta name="viewport" content="width=device-width">时存在一些错误,因此您需要apply the WP8 IE10-specific hack detailed in the Bootstrap documentation

添加此CSS:

@-webkit-viewport   { width: device-width; }
@-moz-viewport      { width: device-width; }
@-ms-viewport       { width: device-width; }
@-o-viewport        { width: device-width; }
@viewport           { width: device-width; }

这个JavaScript:

if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  var msViewportStyle = document.createElement('style');
  msViewportStyle.appendChild(
    document.createTextNode(
      '@-ms-viewport{width:auto!important}'
    )
  );
  document.querySelector('head').appendChild(msViewportStyle)
}

或者你可以等待Windows Phone 8.1,据说这个bug已修复。