我有这段代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" />
</head>
<body>
<div class="container">
<div class="form-wrapper">
<div class="col-md-6 col-md-offset-3 col-sm-12">
<div class="form-group">
<label for="username">Usuario</label>
<input type="text" id="username" class="form-control" />
</div>
</div>
<div class="col-md-6 col-md-offset-3 col-sm-12">
<div class="form-group">
<label for="password">Contraseña</label>
<input type="password" id="password" class="form-control" />
</div>
</div>
<div class="col-md-12 text-center">
<button class="btn btn-primary">Enviar</button>
</div>
</div>
</div>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
和css
.form-wrapper{
padding-top: 25%;
border: 1px solid black;
}
我认为.form-wrapper
内容在div中,但是当我添加边框时,这就是结果
我不知道输入是如何在div boders之外的
答案 0 :(得分:1)
通过在row
内添加container
来关注自举规则,问题将得到解决。
顺便说一下,问题只出现在整个宽度上,而且与浮动没有被正确清除有关,即使没有指定填充顶部也会出现
.form-wrapper {
padding-top: 25%;
border: 1px solid black;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="form-wrapper row">
<div class="col-md-6 col-md-offset-3 col-sm-12">
<div class="form-group">
<label for="username">Usuario</label>
<input type="text" id="username" class="form-control" />
</div>
</div>
<div class="col-md-6 col-md-offset-3 col-sm-12">
<div class="form-group">
<label for="password">Contraseña</label>
<input type="password" id="password" class="form-control" />
</div>
</div>
<div class="col-md-12 text-center">
<button class="btn btn-primary">Enviar</button>
</div>
</div>
</div>