英文:
Do not put the label inline in a form-inline - Bootstrap
问题
Sure, here's the translated content:
我有一个表单,在这个表单中有两个字段排成一行,因为它们在一个 form-inline 的 div 中,我想把这两个字段的标签放在它们上方而不是旁边。如何去掉它们的 form-inline 标签而不影响字段?
以下是代码部分的链接:
CodePen 链接
<main id="contact_part">
<article class="mb-5 row">
<h1>联系我们</h1>
<div class="col-md-12">
<form action="" method="post" id="contact_form">
<div class="form-inline">
<label class="" for="name_contact">姓名</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="name_contact" placeholder="名字" required>
<label class="" for="lastNameContact">姓氏</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="lastName_contact" placeholder="姓氏" required>
</div>
<div class="form-group">
<label class="" for="email_contact">电子邮件</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="电子邮件" required>
</div>
<div class="form-group">
<label class="" for="message_contact">消息</label>
<textarea class="form-control" id="message_contact" placeholder="消息" required></textarea>
</div>
</form>
</div>
</article>
</main>
#contact_part article {
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
#contact_part .row {
display: block;
}
#contact_part h1 {
font-size: 1.7rem;
text-transform: uppercase;
margin-bottom: 3rem;
text-decoration: underline;
text-align: center;
}
#contact_form {
width: 50%;
margin: 0 auto;
}
#contact_form .form-inline label {
}
#contact_form input, #contact_form textarea {
border: none;
border-bottom: 1px solid #C6C6C6;
background-color: #FFF989;
}
英文:
I have a form, I have in this two fields inline because they are in a form-inline div, I want to put the label of these above the fields and not next to them. How to remove form-inline from them without affecting the fields?
<main id="contact_part">
<article class="mb-5 row">
<h1>Nous Contacter</h1>
<div class="col-md-12">
<form action="" method="post" id="contact_form">
<div class="form-inline">
<label class="" for="name_contact">Name</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="name_contact" placeholder="Nom" required>
<label class="" for="lastNameContact">Name</label>
<input type="text" class="form-control mb-2 mr-sm-2" id="lastName_contact" placeholder="Prénom" required>
</div>
<div class="form-group">
<label class="" for="email_contact">E-Mail</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="E-Mail" required>
</div>
<div class="form-group">
<label class="" for="message_contact">Message</label>
<textarea class="form-control" id="message_contact" placeholder="Message" required></textarea>
</div>
</form>
</div>
</article>
</main>
#contact_part article {
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
#contact_part .row {
display: block;
}
#contact_part h1 {
font-size: 1.7rem;
text-transform: uppercase;
margin-bottom: 3rem;
text-decoration: underline;
text-align: center;
}
#contact_form {
width: 50%;
margin: 0 auto;
}
#contact_form .form-inline label {
}
#contact_form input, #contact_form textarea {
border: none;
border-bottom: 1px solid #C6C6C6;
background-color: #FFF989;
}
答案1
得分: 2
如果我理解正确,您无需使用form-inline
类,而是可以像下面的代码一样使用。您的表单将看起来很好。
<main id="contact_part">
<div class="container">
<article class="mb-5 row">
<div class="col-12">
<h1>Nous Contacter</h1>
</div>
<div class="col-12">
<form action="" method="post" id="contact_form">
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="name_contact">姓</label>
<input type="text" class="form-control" id="name_contact" placeholder="姓" required>
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="lastNameContact">名</label>
<input type="text" class="form-control" id="lastName_contact" placeholder="名" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="email_contact">电子邮件</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="example@example.com" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="message_contact">留言</label>
<textarea class="form-control" id="message_contact" placeholder="留言" rows="5" required></textarea>
</div>
</div>
</div>
</form>
</div>
</article>
</div>
</main>
为了更好的性能,请使用col-12
而不是col-md-12
类。不要在没有container
或container-fluid
的情况下使用row
。如果只使用row
,会出现水平滚动条。您的代码将如下所示:
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
或者
<div class="container-fluid">
<div class="row">
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
</div>
</div>
流式视图或100%浏览器宽度
<div class="container-fluid">
<div class="row">
<div class="col-12">内容</div>
<div class="col-12">内容</div>
<div class="col-12">内容</div>
<div class="col-12">内容</div>
</div>
</div>
希望这对您有所帮助!
英文:
If I understand correctly you no need to use form-inline
class
instead use like below code. Your form will look good.
<main id="contact_part">
<div class="container">
<article class="mb-5 row">
<div class="col-12">
<h1>Nous Contacter</h1>
</div>
<div class="col-12">
<form action="" method="post" id="contact_form">
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="name_contact">First Name</label>
<input type="text" class="form-control" id="name_contact" placeholder="First Name" required>
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<label class="custom-control pl-0" for="lastNameContact">Last Name</label>
<input type="text" class="form-control" id="lastName_contact" placeholder="Last Name" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="email_contact">E-Mail</label>
<input type="email" name="email_contact" id="email_contact" class="form-control" placeholder="example@example.com" required>
</div>
</div>
<div class="col-12">
<div class="form-group">
<label class="custom-control pl-0" for="message_contact">Message</label>
<textarea class="form-control" id="message_contact" placeholder="Message" rows="5" required></textarea>
</div>
</div>
</div>
</form>
</div>
</article>
</div>
</main>
Use col-12
instead of col-md-12
class
for better performance. Don't use row
without container
or container-fluid
. If you use only row
it give you horizontal
scroll bar
. Your code
will look like this.
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
Or
<div class="container-fluid">
<div class="row">
<div class="container">
<div class="row">
<div class="col-12"></div>
</div>
</div>
</div>
</div>
Fluid view or 100% Browser width
<div class="container-fluid">
<div class="row">
<div class="col-12">Content</div>
<div class="col-12">Content</div>
<div class="col-12">Content</div>
<div class="col-12">Content</div>
</div>
</div>
> Hope this help!
1: https://codepen.io/rahulmoral/pen/dyPJeNG
答案2
得分: 1
尝试这个,
.form-inline label
{
margin-bottom:3em;
}
或者你可以将标签移到<div class="form-inline">
之外。
英文:
Try this,
.form-inline label
{
margin-bottom:3em;
}
Or You can move the label outside the<div class="form-inline">
答案3
得分: 1
这里是你需要的翻译:
这是您要的翻译:
<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->
<!-- 语言:lang-js -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!-- 语言:lang-css -->
#contact_part{
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
<!-- 语言:lang-html -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<!------ 在 HEAD 标签中包含以上内容 ---------->
<main id="contact_part">
<div class="container ">
<div class="row">
<h2>带有输入字段上方标题的内联表单</h2>
</div>
<form action="#">
<div class="row">
<div class="col-md-3">
<div class="form-group form-group-sm">
<label for="firstname" class="control-label">名字1</label>
<input type="text" class="form-control" id="firstname" placeholder="名字">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">姓氏2</label>
<input type="text" class="form-control" id="lastname" placeholder="姓氏">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">姓氏3</label>
<input type="text" class="form-control" id="lastname" placeholder="姓氏">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<textarea class="form-control"></textarea>
</div>
</div>
<div class="row">
<div class="col-xs-3"><br>
<button type="submit" class="btn btn-default">提交</button>
</div>
</div>
</form>
</div>
</div>
<!-- 结束代码片段 -->
这是你需要的内容的翻译,不包括代码部分。
英文:
Here you go, let me know if this works: https://codepen.io/luke-richter/pen/XWJVqWO
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!-- language: lang-css -->
#contact_part{
background-color: #FFF989;
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
color: #565656;
padding: 50px;
}
<!-- language: lang-html -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<!------ Include the above in your HEAD tag ---------->
<main id="contact_part">
<div class="container ">
<div class="row">
<h2>Inline form with heading above inputs</h2>
</div>
<form action="#">
<div class="row">
<div class="col-md-3">
<div class="form-group form-group-sm">
<label for="firstname" class="control-label">Firstname1</label>
<input type="text" class="form-control" id="firstname" placeholder="Firstname">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">Last Name2</label>
<input type="text" class="form-control" id="lastname" placeholder="Last Name">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="lastname" class="control-label">Last Name3</label>
<input type="text" class="form-control" id="lastname" placeholder="Last Name">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<textarea class="form-control"></textarea>
</div>
</div>
<div class="row">
<div class="col-xs-3"><br>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论