html - Boostrap 4 form messes alignment
问题描述
I have the folowing code that renders different from what I was expecting when you add the form tag. Try removing the form tags to see the difference.
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" integrity="sha256-+N4/V/SbAFiW1MPBCXnfnP9QSN3+Keu+NlB+0ev/YKQ=" crossorigin="anonymous" />
<title>Hello, world!</title>
<style>
html, body {
height: 100%;
}
.min-100 {
min-height: 100%;
}
.fondo {
background-image: url('https://source.unsplash.com/uR6dIgDnt38/1920x1080');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.sombra{text-shadow: 1px 1px 2px rgb(0, 0, 0);}
</style>
</head>
<body>
<div class="container-fluid min-100 d-flex flex-column">
<div class="row flex-grow-1 vh-100 bg-info">
<main class="col p-4 flex-grow-1 fondo">
<div class="container d-flex h-100">
<div class="row justify-content-center align-self-center col-md-12">
<h1 class="text-white mb-4 sombra">Title</h1>
<form action="">
<div class="form-group col-md-12">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fas fa-link"></i></span>
</div>
<input type="text" class="form-control" placeholder="Upload File">
<div class="input-group-append">
<button class="btn btn-success">Guardar</button>
</div>
</div>
</div>
</form>
<p class="text-white lead sombra">A paragraph!</p>
</div>
</div>
</main>
</div>
</div>
</body>
</html>
I want it to look like the second picture, but dont know why the form tag changes the alignment.
解决方案
你的表单标签应该有一个col-sm-12
类
<form action="" class="col-sm-12">
...
</form>
推荐阅读
- python - 如何检查函数将返回什么值
- python - 使用字符串添加新列包含 python
- javascript - 使用 for 循环创建具有唯一 ID 的每个对象
- python - 如何在 Django 3.2 中通过 ForeignKey 获取对象
- android - 检测安卓设备重启
- python - 如何修复 Python 循环导入错误(顶级)?
- java - XPath 查找具有某些属性值的子项
- parallel-processing - 优化 PBS 队列系统中的模拟
- postgresql - 不支持的功能:7 错误:从 Mysql 5.5 迁移到 Postgresql 10 后,FOR UPDATE 不能应用于外连接的可空端
- node.js - Sequlizer 内连接