为什么赢得我的表单显示?

时间:2014-04-06 14:35:46

标签: html twitter-bootstrap twitter-bootstrap-3

我使用带有Bootswatch主题的Bootstrap 3。这是我的HTML:

<!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>Title</title>

    <!-- Bootstrap -->
    <link href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/flatly/bootstrap.min.css" rel="stylesheet">

    <!-- 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/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>

    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" data-toggle="collapse" data-target=".navbarcollapse" class="navbar-toggle">
                    <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="#">LicenseApp</a>
            </div>
            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Dashboard</a></li>
                    <li><a href="#">Nav 1</a></li>
                    <li><a href="#">Nav 2</a></li>
                </ul>
            </div>
        </div>
    </div>

    <div class="container">


    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" role="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="">Username</label>
                    <div class="col-sm-10">
                        <input class="form-control" name="username" type="text" />
                    </div>
                </div>
            </form>
        </div>
    </div>


    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html>

为什么我有这么多问题的任何想法?我错过了DIV还是什么?

2 个答案:

答案 0 :(得分:1)

您的表单位于导航栏下方,因为导航栏固定在顶部。

遵循以下css规则:

.navbar-fixed-top {
   top: 0;
   border-width: 0 0 1px;
}

因此,要么将表单向下推或使导航栏不固定,例如从此元素中删除navbar-fixed-top

<div class="navbar navbar-default navbar-fixed-top" role="navigation">

因此,它会显示 jsfiddle example

或者@ Jamesking56注意到,将navbar-fixed-top更改为navbar-static-top有效

答案 1 :(得分:0)

在Bootstrap中,当使用固定的导航标题时,通常会在主体上放置一个填充顶部,与标题的高度相同。

见这里:Bootstrap docs

  

需要身体填充

     

固定导航栏将覆盖您的其他内容,除非您在主体顶部添加填充。尝试自己的价值观或使用下面的代码段。提示:默认情况下,导航栏高50像素。

     

body {padding-top:70px; }

     

确保在核心Bootstrap CSS之后包含此内容。