gpt4 book ai didi

css - 使用 d-inline-block Bootstrap 内联

转载 作者:行者123 更新时间:2023-11-28 14:56:57 25 4
gpt4 key购买 nike

我正在提高我的 Bootstrap 技能,我想知道为什么在一个地方内联一项工作而在另一个地方内联,这里:d-inline-block 和这个 form-inline,这两者之间有什么区别以及为什么在“d-inline-block”的地方使用“form-inline”行不通?两者都有表单类?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<style>
body{
padding:0px;
margin:0px;}



</style>
</head>
<body>

<div class="form-group form-inline pt-4">
<div class="col-sm-10">
<div class="fas fa-lock"></div> <input type="password" class="form-control" id="pwd" placeholder=" password" name="pwd">
</div>
</div>
<div class=" ">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
</div>
</div>
</div>
<div class="form-group d-inline-block">
<button type="submit" class="btn btn-success ml-3">Login</button>
</div>
<div class="form-group d-inline-block">
<button type="submit" class="btn btn-primary">Login with facebook</button>
</div>
</div>
</form>
</div>

</body>
</html>

最佳答案

不同之处在于 .form-inline 允许您将标签与相关输入对齐。 .form-inline 应该应用于 form 元素。当您将 .d-inline-block 应用于 form-groups 时,您可以将它们排成一行,但标签将保留在顶部。检查下面的代码片段以查看不同之处:

form {
border: 2px solid black;
padding: 10px;
margin: 10px;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<style>
body {
padding: 0px;
margin: 0px;
}
</style>
</head>

<body>
<h6>Inline form</h6>
<form class="form-inline">

<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>

<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>

<div class="form-group d-inline-block">
<button type="submit" class="btn btn-success ml-3">Login</button>
<button type="submit" class="btn btn-primary">Login with facebook</button>
</div>
</form>
<h6>Not inline form with .form-group.d-inline-block</h6>
<form>
<div class="form-group d-inline-block">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>

<div class="form-group d-inline-block">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>

<div class="form-group d-inline-block">
<button type="submit" class="btn btn-success ml-3">Login</button>
<button type="submit" class="btn btn-primary">Login with facebook</button>
</div>
</form>
</body>
</html>

关于css - 使用 d-inline-block Bootstrap 内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50789465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com