3

我已经开始探索 Twitter Bootstrap,并尝试编写或复制他们的一些示例代码。我使用带有 .container 类的 div 作为包装器,并在其中添加了一些行和列。拥有一个带有 .container 类的 div 应该会自动将 div 居中,但就我而言,我的内容不平衡。左侧的空白区域比右侧的空白区域宽得多。这是代码(我没有使用任何 CSS 样式):

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>The Room</title>

    <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link rel='stylesheet' href='style.css' />
    <!--responsive bootsrap here-->
    <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/functions.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container">
        <div class="row"></div>
        <div class="span12">
            <div class="navbar navbar-inverse">
                    <div class="navbar-inner">
                        <a href="#" class="brand">The Room</a>
                    <ul class="nav">
                        <li class="active"><a href="#">Home</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">Preview</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">Blog</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">About</a></li>
                        <li class="divider-vertical"></li>
                    </ul>
                    <form class="navbar-search">
                        <input type="text" class="search-query" placeholder="Search for...">
                    </form>
                </div>
            </div>
        </div> <!-- first row -->
        <div class="span12">
            <div class="hero-unit">
                <h1>Hey Mark! <small>and everybody!</small></h1>
                <p>Hey Mark! I am Johnny, I am super boring, I love to play football, and I am very passionate about film making. I love the idea on sucking on making films, spending $6m for my first feature film, which is my masterpiece of course! The title of my masterpiece, is "The Room" very catchy right? No, I did not hit her! I did not hit her! I did NOT!</p>

                <p>
                    <a class="btn btn-primary btn-large">Watch Movie</a>`enter code here`
                </p>
            </div>
        </div><!-- second row -->
        </div>
    </div>
</body>

</html>

这是屏幕截图: https ://dl.dropboxusercontent.com/u/70465637/error_center.jpg

注意左边的空白是如何比右边的空白更宽的。

请帮助,在此先感谢。

4

4 回答 4

2

Your div.span12 should be a child of div.row.

<div class="row">
  <div class="span12"></div>
</div>
于 2013-06-28T11:17:16.513 回答
2

用这个替换body标签

<body>
    <div class="container">
        <div class="row">

        <div class="span12">
            <div class="navbar navbar-inverse">
                <div class="navbar-inner">
                    <a href="#" class="brand">The Room</a>
                    <ul class="nav">
                        <li class="active"><a href="#">Home</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">Preview</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">Blog</a></li>
                        <li class="divider-vertical"></li>
                        <li><a href="#">About</a></li>
                        <li class="divider-vertical"></li>
                    </ul>
                    <form class="navbar-search">
                    <input type="text" class="search-query" placeholder="Search for...">
                    </form>
                </div>
            </div>
        </div>
        <!-- first row -->
        </div>
        <div class="row">
        <div class="span12">
            <div class="hero-unit">
                <h1>
                    Hey Mark! <small>and everybody!</small></h1>
                <p>
                    Hey Mark! I am Johnny, I am super boring, I love to play football, and I am very
                    passionate about film making. I love the idea on sucking on making films, spending
                    $6m for my first feature film, which is my masterpiece of course! The title of my
                    masterpiece, is "The Room" very catchy right? No, I did not hit her! I did not hit
                    her! I did NOT!</p>
                <p>
                    <a class="btn btn-primary btn-large">Watch Movie</a>`enter code here`
                </p>
            </div>
        </div>
        <!-- second row -->
        </div>
    </div>
    </div></body>
于 2013-06-28T11:36:49.723 回答
1

正确检查你的代码你的 span12div 应该在里面<div class="row"></div>

你的代码应该是这样的

<div class="container">

  <div class="row">
      <div class="span12"> your content goes here </div>
  </div>

</div>
于 2013-06-28T11:27:29.477 回答
0

如果在将 span12 div 放入行后仍然遇到空格问题,那么可能是因为 Bootstrap 指定了自己的边距和填充等。

您可能必须为跨度设置自己的边距或填充。您可以使用 !important 声明覆盖 CSS 中的引导样式:

.span12 {
  margin-left: -50px !important;
}
于 2013-06-28T11:31:23.797 回答