I have a 4-column horizontal form in Bootstrap 3 (latest version):
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>Title is here</h1>
</div>
</div>
<div class="row">
<div class="col-xs-12 no-gutter">
<form class="form-horizontal">
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Title">
</div>
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Title">
</div>
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Email Address">
</div>
<div class="col-md-3">
<button type="submit" class="form-control input-lg btn-danger">Check The Price</button>
</div>
</form>
</div>
</div>
And the following CSS (to make the input fields next to each other):
.col-xs-12.no-gutter [class*='col-'] {
padding-right: 0;
padding-left: 0;
}
Here's the issue. I want the button to be smaller (for it to take 2 columns instead of 3). So I changed the last <div> from col-md-3 to col-md-2 and got this:
http://www.bootply.com/JiNeG04Ifl
The code is the same like the pasted code above, just with the last <div> changed to col-md-2. Now, try to resize the viewport from 1194px to 992px (the medium size after the forms are switching to vertical). You will notice that the text overflows the box, although there is more than enough white space in the button itself.
How can I fix this? So far I've tried:
white-space: nowrap;
But the problem with this is that the text does not stay centered in the box, its alignment seems to be going off. Is there some better solution to keep the alignment centered?
Remove the l/r padding from the button...
.input-lg.btn-danger {
padding-left: 0;
padding-right: 0;
}
http://www.bootply.com/QkBiP8yHNE
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
/* CSS used here will be applied after bootstrap.css */
.margin-bottom-30 {
margin-bottom: 30px;
}
.margin-top-30 {
margin-top: 30px;
}
.col-xs-12.no-gutter [class*='col-'] {
padding-right: 0;
padding-left: 0;
}
* {
border-radius: 0 !important;
}
.input-lg.btn-danger {
padding-left: 0;
padding-right: 0;
}
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="margin-bottom-30">Title Here</h1>
</div>
</div>
<div class="row no-gutter">
<div class="col-xs-12 form no-gutter">
<form class="form-horizontal">
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Title">
</div>
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Title">
</div>
<div class="col-md-3">
<input type="text" class="form-control input-lg" placeholder="Your Email Address">
</div>
<div class="col-md-2">
<button type="submit" class="form-control input-lg btn-danger">Check The Price</button>
</div>
</form>
</div>
</div>
</div>
<div id="push"></div>
Related
In this simple example, when I have a validation error on the First Name input box on the left side of the form, the E-Mail form element gets pushed down the page.
When I have the same error on the right side of the form though, this behavior does not happen.
I don't see any difference in the code. Here are some screen shots. I was unable to get this to work in jsfiddle or codepen, so here is the link to the test page and I've also pasted my html below:
https://www.blastyourresume.com/testing/formalignment/test.cfm
To reproduce the error on that page, type something in the firstname field, then delete it. If you repeat this process on the right side, you don't get the same behavior.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container" align="center">
<form name="frmSignup" id="frmSignup" method="post">
<div class="col-sm-6 col-xs-12 col-md-6">
<div class="form-group" align="left">
<label>First Name</label>
<input type="text" placeholder="First Name" id="firstname" name="firstname" maxlength="50" class="form-control">
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-6">
<div class="form-group" align="left">
<label>Last Name</label>
<input type="text" placeholder="Last Name" id="lastname" name="lastname" maxlength="50" class="form-control">
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-6">
<div class="form-group" align="left">
<label>E-Mail Address</label>
<input type="text" placeholder="E-Mail" id="email" name="email" maxlength="100" class="form-control">
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-6">
<div class="form-group" align="left">
<label>Confirm E-Mail Address</label>
<input type="text" placeholder="Confirm E-Mail" id="confirmemail" name="confirmemail" maxlength="100" class="form-control">
</div>
</div>
<div class="col-sm-12 col-xs-12 col-md-12">
<button type="submit" name="btnSubmit" class="btn btn-primary" id="btnSubmit"> Submit </button>
</div>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
Flex approach
add display:flex to your parent container. Display flex will make
your columns equal height.
#frmSignup {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
Absolute positioning of error messages.
.form-group {
position: relative;
}
.errormessageclass {
position: absolute;
top: 100%;
left: 0;
width: 100%;
}
For some reason when validation message is shown for the first name input it causes email field to be pushed left and confirm email goes to the next row. I found that it could be fixed if you wrap you form groups in <div class="row"></div> like:
<div class="row">
<div class="col-sm-6 col-xs-12 col-md-6" style="">
<div class='form-group>first name</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-6" style="">
<div class='form-group>last name</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-xs-12 col-md-6" style="">
<div class='form-group>email</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-6" style="">
<div class='form-group>confirm email</div>
</div>
</div>
https://codepen.io/
But it sound like a rough hack.
I also would be grateful to get an explanation of why pushing effect happens.
I have the below HTML and CSS - how do I make the search-bar and add-contacts the same height? I currently have their height set to 100% in CSS to expand inside their container div but that doesn't work Is it possible to change their height even though they are bootstrap units?
HTML
<div className="container">
<form className="form-inline search-bar" role="form">
<div className="form-group has-success has-feedback">
<label className="control-label" htmlFor="inputSuccess4"></label>
<input type="text" className="form-control" id="inputSuccess4" type="text" placeholder="Search" onChange={handleChange}/>
<span className="glyphicon glyphicon-search flipped form-control-feedback"></span>
</div>
</form>
<div className="add-contacts">
<button type="button" className="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
+ Contacts Keeper
</button>
</div>
</div>
CSS
.table-container {
margin: 20px;
}
.search-bar {
margin-left: 20px;
float: left;
height: 100%;
}
.add-contacts {
margin-right: 20px;
float: right;
height: 100%;
}
Just change the height of the search bar.
Or you could put search bar in same div as add contacts bar.
I find simpler is better with Bootstrap. I try to avoid adding custom CSS for most of the HTML elements already styled by Bootstrap:
<div class="container">
<div class="row">
<div class="col-md-12">
<form class="form-horizontal">
<div class="col-md-3 text-left">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Search</label>
<div class="input-group">
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Search">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
</div>
</div>
</div>
<div class="col-md-6"></div>
<div class="col-md-3 text-right">
<button type="submit" class="btn btn-primary">+ add stuff</button>
</div>
</form>
</div>
</div>
</div>
I am using bootstrap's form controls, and I want to be able to create a collapsible set of input elements, each called a section, and have the sections have a border around them.
But, the input elements inside the sections don't extend the entire width on medium or large displays, so I don't want the border to extend the entire width of the screen.
I know I can use a ::after pseudo class to make the border not extend the entire width, but the actual width needs to be responsive.
Is there a way to incorporate the bootstrap media queries in the pseudo style?
Or is there an easier way to accomplish what I want?
The other issue, is that by wrapping the sections in a div with a col-md-xx, then everything inside the div (all the rows) inherit the new width, which is also a problem.
Here is the sample code I've come up with so far:
<form class="form-horizontal">
<div class="col-md-12">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email </label>
<div class="col-md-6">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</div>
<div class=" col-md-12 q collapse in">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email 2</label>
<div class="col-md-6">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email 3</label>
<div class="col-md-6">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</div>
<div class="form-group "></div>
<div class="form-group ">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
Here is style:
div.q:after {
content: "";
position: absolute;
left: 9%;
bottom: 10px;
top: -10px;
height: 100%;
width: 60%; /* or 100px */
border-width: 2px 2px 2px 2px;
border-style: solid;
border-color: black;
border-radius: 0px;
padding: 50px;
}
The width can't be set to a fixed number, either percentage or px, because on small devices the border should be 100%.
Would it just be easier to add border styling to each label / input div, rather than trying to wrap the sections in a div?
div class="container">
<div class="row">
<div class="col-md-6">
<form class="form-inline" action="#" method="POST" role="form" name="myForm" style="margin-top: 50px;">
<div class="well">
<div class="form-group col-sm-12">
<label class="Control-label col-sm-4" id=""> Email:</label>
<label class="Control-label col-sm-4" id=""> Username:</label>
<label class="Control-label col-sm-4" id=""> Password:</label>
</div>
<div class="row">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
<h1> Test </h1>
</div>
</div>
</form>
</div>
</div>
and my CSS code is :
.form-control{
width: 150px;
}
h1{
color:red;
}
Good Day mate, i am just confuse if im doing right or not. i want to resize the input on my website which defined as class "form-control" but when i do the css above nothing changes. can someone help me if my selector or wrong or my codes is? thank you
P.S the test below is just a xample if the css is being link in my editor and yes the color red is being executed
The more specific the selector, the more precedence it has. For example :
.mydiv .myclass {
background-color: blue;
}
.myclass {
background-color: red;
}
Even tho the red background is defined after the blue one, the first one is more specific in the class that it is applied to, and in case you have the following code, the blue background will be applied :
<div class="mydiv">
<div class="myclass">
</div>
</div>
So what you want to do in your case, and this is the most basic but still the better solution, is to add a class to your form in order to be able to specify the width of the form-control elements for this form :
<form class="form-inline cool-form">
<div class="well">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
</div>
</form>
And then specify the width in your css :
.cool-form .form-control {
width: 250px;
}
try this:
note: and you are missing to close your first div i.e <div class="container">
.form-control::-webkit-input-placeholder {
color: red;
width: 250px;
}
h1 {
color: red;
}
<div class="container">
<div class="row">
<div class="col-md-6">
<form class="form-inline" action="#" method="POST" role="form" name="myForm" style="margin-top: 50px;">
<div class="well">
<div class="form-group col-sm-12">
<label class="Control-label col-sm-4" id="">Email:</label>
<label class="Control-label col-sm-4" id="">Username:</label>
<label class="Control-label col-sm-4" id="">Password:</label>
</div>
<div class="row">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
<h1> Test </h1>
</div>
</div>
</form>
</div>
</div>
You are using Bootstrap and form-control class is used from Bootstrap CSS.
Use (Easy way)
.form-control{
width: 150px !important;
}
to override your code over Bootstrap CSS
The best practice -
In your case the class is .form-control (Bootstrap class)
To overcome this is to define new class and add new changes to your own class.
.form-control-override{
width: 150px;
}
and use this form-control-override in your HTML code instead of form-control
I am using bootstrap 3 in my website.
I created a row that looks like the following image, within this row, i've created 4 columns:
Left: picture
L-R: text
L-L: Input
Right: Button
Where is my problem ?
1. Set the user/password/input/login button to the left of the columns
2. set button height small
3. "Forgot your password" to be in 1 line and not 2 lines.
Like the following picture:
I am new to HTML/CSS. How can i achieve it ?
Here is my code:
<div class="row loginBody">
<div class="col-md-4 "></div>
<div class="col-md-4 ">
<div class="container-fluid InputLoginDetails LoginFont">
<div class="row LoginRow">
<div class="col-md-4"><img src="img/Hello.png" class="img-responsive" /></div>
<div class="col-md-2">
User:
Password:
</div>
<div class="col-md-3 ">
<input type="text" class="form-control">
<input type="text" class="form-control">
<p>Forgot your password?</p>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary ">Login</button>
</div>
</div>
</div>
</div>
.loginBody{
background-color: #808689;
margin: auto;
margin-top: 5%;
border-radius: 5px;
}
.LoginRow{
padding-top: 3%;
padding-bottom: 3%;
background-color: white;
}
.LoginFont{
font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
color: #7296cd;
font-size: 1em;
font-weight: bold;
padding-top: 5%;
}
.InputLoginDetails input[type="text"] {
height: 1.1em;
font-size: 0.9em;
}
I changed several things in your HTML markup.
1.) You don't use .container classes within a row, they are just used as containers outside of rows.
Note that, due to padding and more, neither container is nestable.
Bootstrap Containers
2.) You don't need 4 columns within your '.LoginRow', one for the image and one for the form elements are sufficient and give you more flexibility.
3.) Use the horizontal forms markup of bootstrap to create the form layout.
4.) All in all, you need to take a closer look at the Bootstrap docs and their examples, especially the grid system. Then it is really easy to do a lot of things.
Here is your changed HTML markup:
<div class="row loginBody">
<div class="col-md-4 "></div>
<div class="col-md-4 ">
<div class="InputLoginDetails LoginFont">
<div class="row LoginRow">
<div class="col-md-4"><img src="http://placehold.it/200x200" class="img-responsive"></div>
<div class="col-md-8">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">User</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<p>Forgot your password?</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
You said you wanted to align the User/Password label to the left. Since the bootstrap default labes are aligned to the right, I created this CSS additionally:
.LoginRow .form-group label {
text-align: left;
}
And here is a working bootply
If I understood correctly, and with the code you have provided. I think you didnt have to add both labels with the same div and input boxes. Please check the fiddle to see if thats what you wanted.
I also removed the <p> tag from "Forgot your password".
I changed
<div class="col-md-2">
User:
Password:
</div>
To
<div class="col-md-2">
User:
<input type="text" class="form-control">
</div>
Fiddle