我试图将容器对准页面的中间,但它似乎卡在了页面的顶部。
我读过类似的question,但它们似乎没有用。我复制了一些代码片段,但在我的firefox浏览器中,它们似乎仍然停留在页面顶部。我不确定这是否是浏览器问题。
这是我的代码。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<div class="container d-flex justify-content-center h-100 mx-auto">
<div class="row justify-content-center">
<div class="col">
<div class="card text-center" style="min-width: 23rem; max-width: 23rem;">
<div class="card-header bg-success text-white text-center">Login</div>
<div class="card-body">
<form>
<div class="form-row mb-2">
<label for="username">Username</label>
<input type="text" class="form-control" id="username">
</div>
<div class="form-row mb-4">
<label for="Password">Password</label>
<input type="password" class="form-control" id="password">
</div>
<div class="row">
<div class=" col text-center">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!--
<div class="container-fluid h-100 d-flex flex-column justify-content-center">
<div class="row justify-content-center bg-info">
<div class="col-4">
<div class="card">
<div class="card-header">Access</div>
<div class="card-body">
<div class="form-group">
Nullam sapien massa, aliquam in cursus ut, ullamcorper in tortor. Aliquam codeply mauris arcu, tristique a lobortis vitae, condimentum feugiat justo.
</div>
</div>
<div class="card-footer text-right">
<button type="submit" class="btn btn-danger">ok</button>
</div>
</div>
</div>
</div>
</div> -->
</body>
</html>
答案 0 :(得分:0)
您可以通过添加以下内容来实现所需的行为:
align-items: center;
Css样式为class =“ container-fluid”。
答案 1 :(得分:0)
这是您可以做到的!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<style> <--- Added style tag
.box{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div class="box container d-flex justify-content-center mx-auto">
<div" class="justify-content-center">
<div class="col">
<div class="card text-center" style="min-width: 23rem; max-width: 23rem;">
<div class="card-header bg-success text-white text-center">Login</div>
<div class="card-body">
<form>
<div class="form-row mb-2">
<label for="username">Username</label>
<input type="text" class="form-control" id="username">
</div>
<div class="form-row mb-4">
<label for="Password">Password</label>
<input type="password" class="form-control" id="password">
</div>
<div class="row">
<div class=" col text-center">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>