inline form parts using CSS (inline attribute)? - css

I want to create a simple form. The final design should be the one above, but with a responsive positioning.
So I tried to use the inline attribute of css:
<!--Name...-->
<div style="display: inline;">
<label for="vorname_patient">Vorname: </label> <br> <input type="text" name="vorname_patient" id="vorname_patient" required="" size="20" autofocus=""> <br>
<label for="nachname_patient">Nachname: </label> <br> <input type="text" name="nachname_patient" id="nachname_patient" required="" size="20">
</div>
<!--Anrede...-->
<div style="display: inline;">
<label for=anrede_patient">Anrede: </label> <br> <input type="text" name="anrede_patient" id="anrede_patient" size="20">
</div>
If i run that i will not get any inlineme parts anywhere.
i want to get this (without a table):
https://jsfiddle.net/kcd1qr1r/
What did I do wrong here? Thank you!

Inline elements must flow within their nearest block parent. So, because you changed the div containers to be inline, your label and input elements are just flowing within the body (nearest block parent). Use inline-block instead or, due to possible margin issues with that approach, you may want to try flexboxes.

Related

Sibling Elements with 100% Widths Aren't the Same Width?

This is driving me crazy. I've got a few sibling elements in the same form, input fields and divs (that contain input fields that need to stay on the same line), but when 100% width is applied to each, they aren't the same length; the divs are the same length as the other divs, and the independent inputs are the same as the other inputs. I've tried everything I can think of, and I can't figure out what's causing this behavior. It's messing-up my responsive styling, so I've come to a bit of a standstill...
If the width is 100%, and the elements are direct siblings of the same parent element, they SHOULD have equal widths, correct? In the screenshots below, the inputs inside the "bi-field-div" and "tri-field-div" elements are shorter, and the inputs that aren't inside a div are longer, even though the divs and inputs are both children of the same form element and are set to 100% (the one input you see in a class-less, id-less div still renders the same length as if there were no div at all-- I put it in there to test it.) I've tried extending the inputs within the divs by way of different percentages and margins and padding, but the div itself stays that shorter length, so the inputs within it just end up on different lines at a certain point; I've also fiddled with the positioning, displays, and everything else, and just can't get these stubborn things to stretch out equally!
I'll greatly appreciate any constructive advice you can give me.Thank you.
HTML:
<form>
<!-- pop-out text -->
<div class="div-form">
<p id="call-to-action">SIGN UP</p>
<p id="sub-text">Subrscribe to our newsletter</p>
<div id="bi-field-div">
<input type="text" class="form-field left-inline-field" placeholder="First Name">
<input type="text" class="form-field right-inline-field" placeholder="Last Name">
</div>
<div>
<input type="text" id="email" class="form-field" placeholder="Email">
</div>
<input type="text" class="form-field" placeholder="Phone" >
<div id="bi-field-div">
<input type="text" class="form-field left-inline-field" placeholder="State / Province">
<input type="text" class="form-field right-inline-field" placeholder="Zip">
</div>
<input type="text" class="form-field" placeholder="Company Name">
<input type="text" class="form-field" placeholder="How did you hear about us?">
<input type="text" class="form-field" placeholder="Company Name">
<div id="tri-field-div">
<input type="text" class="form-field tri-field" placeholder="Experience">
<input type="text" class="form-field tri-field" placeholder="Interests">
<input type="text" class="form-field tri-field" placeholder="Referral?">
</div>
<div class="signup-btn-div">
<button id="signup-btn">
SIGN UP
</button>
</div>
<div id="privacy-policy">
Privacy Policy
</div>
</div>
</form>
CSS:
Form CSS
What it looks like in browser:
Form in browser

How to align input fields like this? (close and sharing border)

I am designing a checkout form and really like how the Stripe checkout forms groups its inputs tightly together as seen here
I use bootstrap 3 and so far I have marked out the structure, but I havent been able to get the inputs and their borders to be aligned neatly like in the picture
My html
<div class="col-xs-12">
<div class="input-grouping">
<div class="top">
<input type="text" class="form-control" id="checkoutCardNumber" placeholder="Card Number">
</div>
<div class="bottom-left">
<input type="text" class="form-control" name="checkoutExpiration" id="checkoutExpiration" placeholder="MM/YY">
</div>
<div class="bottom-right">
<input type="text" class="form-control" id="checkoutCVC" placeholder="CVC">
</div>
</div>
</div>
Any advice?
If I was looking to replicate your example exactly, I would suggest suppressing the default presentation of the input fields (by removing the borders and background) and then wrapping them in divs which you can style as you choose.

Bootstrap - form elements auto layout

I have the following form, I want to have 3 items in a row.
Since it is auto generated I cant really change to much the html.
I cant have dynamic span for each column.
With the limitations I have here, is it possible to break the code bellow so Ill have 3 fields in a row?
http://fiddle.jshell.net/52VtD/446/
<div class="row-fluid">
<input id="Id" name="Id" type="hidden">
<div class="span1">
<label>
Email Address
</label>
<input class="form-control" id="Email" name="Email" type="text">
</div>
<div class="span1">
<label>
Full Name
</label>
<input class="form-control" id="FullName" name="FullName" type="text">
</div>
<div class="span1">
<label>
Active?
</label>
<input class="form-control" id="IsActive" name="IsActive" type="text">
</div>
<div class="span1">
<label>
Password
</label>
<input class="form-control" id="Password" name="Password" type="password">
</div>
<input name="Avatar.Id" type="hidden">
<div class="span1">
<label>
Upload image
</label>
<input class="form-control" id="Avatar.FileContent" name="Avatar.FileContent" placeholder="Select an image" type="file">
</div>
</div>
Sometimes, it helps not over thinking Bootstrap. Also note, this is Bootstrap 3 I'm using.
If you're looking to have "three items" in a row, including the labels, that can be created with 6 columns. 3 per label and 3 per input.
http://fiddle.jshell.net/pLSD9/1/
In this case, you don't use any of the built in form layouts like .form-inline. You use the Bootstrap grid and place your elements in it accordingly. Since Bootstrap gives it's form input elements 100% width, they'll fill the grid space.
I used the "sm" size grid so when the form gets to what Bootstrap considers a "small" size, it will stack the elements. Since JSFiddle brings the page down into windows,you might have to adjust the window size to see the grid layout.
I hope that helps!
Cheers!
You're going to break Bootstrap a lot, but if you could give the container an id and style it this way:
#form-container {
width: 700px;
}
#form-container .row-fluid .span1 {
float: left;
margin-right: 10px;
}
To get this result: http://fiddle.jshell.net/52VtD/448/

Input widths on Bootstrap 3

Update again: I am closing this question by selecting the top answer to keep people from adding answers without really understanding the question. In reality there is no way to do it with the build in functionality without using grid or adding extra css. Grids do not work well if you are dealing with help-block elements that need to go beyond a short input for example but they are 'build-in'. If that is an issue I recommend using extra css classes which you can find in the BS3 discussion here. Now that BS4 is out it is possible to use the included sizing styles to manage this so this is not going to be relevant for much longer. Thanks all for good input on this popular SO question.
Update: This question remains open because it is about built-in functionality in BS to manage input width without resorting to grid (sometimes they have to be managed independently). I already use custom classes to manage this so this is not a how-to on basic css. The task is in BS feature discussion list and has yet to be addressed.
Original Question:
Anyone figure out a way to manage input width on BS 3? I'm currently using some custom classes to add that functionality but I may have missed some non documented options.
Current docs say to use .col-lg-x but that clearly doesn't work as it can only be applied to the container div which then causes all kinds of layout/float issues.
Here's a fiddle. Weird is that on the fiddle I can't even get the form-group to resize.
http://jsfiddle.net/tX3ae/
<form role="form" class="row">
<div class="form-group col-lg-1">
<label for="code">Name</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-lg-1 ">
<label for="code">Email</label>
<input type="text" class="form-control input-normal">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
What you want to do is certainly achievable.
What you want is to wrap each 'group' in a row, not the whole form with just one row. Here:
<div class="container">
<h1>My form</h1>
<p>How to make these input fields small and retain the layout.</p>
<form role="form">
<div class="row">
<div class="form-group col-lg-1">
<label for="code">Name</label>
<input type="text" class="form-control" />
</div>
</div>
<div class="row">
<div class="form-group col-lg-1 ">
<label for="code">Email</label>
<input type="text" class="form-control input-normal" />
</div>
</div>
<div class="row">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
</div>
The NEW jsfiddle I made:
NEW jsfiddle
Note that in the new fiddle, I've also added 'col-xs-5' so you can see it in smaller screens too - removing them makes no difference. But keep in mind in your original classes, you are only using 'col-lg-1'. That means if the screen width is smaller than the 'lg' media query size, then the default block behaviour is used. Basically by only applying 'col-lg-1', the logic you're employing is:
IF SCREEN WIDTH < 'lg' (1200px by default)
USE DEFAULT BLOCK BEHAVIOUR (width=100%)
ELSE
APPLY 'col-lg-1' (~95px)
See Bootstrap 3 grid system for more info. I hope I was clear otherwise let me know and I'd elaborate.
In Bootstrap 3
You can simply create a custom style:
.form-control-inline {
min-width: 0;
width: auto;
display: inline;
}
Then add it to form controls like so:
<div class="controls">
<select id="expirymonth" class="form-control form-control-inline">
<option value="01">01 - January</option>
<option value="02">02 - February</option>
<option value="03">03 - March</option>
<option value="12">12 - December</option>
</select>
<select id="expiryyear" class="form-control form-control-inline">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
</div>
This way you don't have to put extra markup for layout in your HTML.
ASP.net MVC go to Content- Site.css and remove or comment this line:
input,
select,
textarea {
/*max-width: 280px;*/
}
I think you need to wrap the inputs inside a col-lg-4, and then inside the form-group and it all gets contained in a form-horizontal..
<form class="form form-horizontal">
<div class="form-group">
<div class="col-md-3">
<label>Email</label>
<input type="email" class="form-control" id="email" placeholder="email">
</div>
</div>
...
</form>
Demo on Bootply - http://bootply.com/78156
EDIT: From the Bootstrap 3 docs..
Inputs, selects, and textareas are 100% wide by default in Bootstrap. To use the inline form, you'll have to set a width on the form controls used within.
So another option is to set a specific width using CSS:
.form-control {
width:100px;
}
Or, apply the col-sm-* to the `form-group'.
Current docs say to use .col-xs-x , no lg.
Then I try in fiddle and it's seem to work :
http://jsfiddle.net/tX3ae/225/
to keep the layout maybe you can change where you put the class "row" like this :
<div class="container">
<h1>My form</h1>
<p>How to make these input fields small and retain the layout.</p>
<div class="row">
<form role="form" class="col-xs-3">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" >
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
http://jsfiddle.net/tX3ae/226/
<div class="form-group col-lg-4">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
Add the class to the form.group to constraint the inputs
If you are using the Master.Site template in Visual Studio 15, the base project has "Site.css" which OVERRIDES the width of form-control fields.
I could not get the width of my text boxes to get any wider than about 300px wide. I tried EVERYTHING and nothing worked. I found that there is a setting in Site.css which was causing the problem.
Get rid of this and you can get control over your field widths.
/* Set widths on the form inputs since otherwise they're 100% wide */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="select"] {
max-width: 280px;
}
I know this is an old thread, but I experienced the same issue with an inline form, and none of the options above solved the issue. So I fixed my inline form like so:-
<form class="form-inline" action="" method="post" accept-charset="UTF-8">
<div class="row">
<div class="form-group col-xs-7" style="padding-right: 0;">
<label class="sr-only" for="term">Search</label>
<input type="text" class="form-control" style="width: 100% !important;" name="term" id="term" placeholder="Search..." autocomplete="off">
<span class="help-block">0 results</span>
</div>
<div class="form-group col-xs-2">
<button type="submit" name="search" class="btn btn-success" id="search">Search</button>
</div>
</div>
</form>
That was my solution. Bit hacky hack, but did the job for an inline form.
You can add the style attribute or you can add a definition for the input tag in a css file.
Option 1: adding the style attribute
<input type="text" class="form-control" id="ex1" style="width: 100px;">
Option 2: definition in css
input{
width: 100px
}
You can change the 100px in auto
I hope I could help.
In Bootstrap 3
All textual < input >, < textarea >, and < select > elements with .form-control are set to width: 100%; by default.
http://getbootstrap.com/css/#forms-example
It seems, in some cases, we have to set manually the max width we want for the inputs.
Anyway, your example works. Just check it with a large screen, so you can see the name and email fields are getting the 2/12 of the with (col-lg-1 + col-lg-1 and you have 12 columns). But if you have a smaller screen (just resize your browser), the inputs will expand until the end of the row.
You don't have to give up simple css :)
.short { max-width: 300px; }
<input type="text" class="form-control short" id="...">
If you're looking to simply reduce or increase the width of Bootstrap's input elements to your liking, I would use max-width in the CSS.
Here is a very simple example I created:
<form style="max-width:500px">
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Email Address">
</div>
<div class="form-group">
<textarea class="form-control" rows="5" placeholder="Message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
I've set the whole form's maximum width to 500px. This way you won't need to use any of Bootstrap's grid system and it will also keep the form responsive.
I'm also struggled with the same problem, and this is my solution.
HTML source
<div class="input_width">
<input type="text" class="form-control input-lg" placeholder="sample">
</div>
Cover input code with another div class
CSS source
.input_width{
width: 450px;
}
give any width or margin setting on covered div class.
Bootstrap's input width is always default as 100%, so width is follow that covered width.
This is not the best way, but easiest and only solution that I solved the problem.
Hope this helped.
I do not know why everyone has seem to overlook the site.css file in the Content folder. Look at line 22 in this file and you will see the settings for input to be controlled. It would appear that your site is not referencing this style sheet.
I added this:
input, select, textarea { max-width: 280px;}
to your fiddle and it works just fine.
You should never ever update bootstrap.css or bootstrap.min.css. Doing so will set you up to fail when bootstrap gets updated. That is why the site.css file is included. This is where you can make changes to site that will still give you the responsive design you are looking for.
Here is the fiddle with it working
Add and define terms for the style="" to the input field, that's the easiest way to go about it:
Example:
<form>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" style="width:200px;">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" style="width:200px">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Bootstrap uses the class 'form-input' for controlling the attributes of 'input fields'. Simply, add your own 'form-input' class with the desired width, border, text size, etc in your css file or head section.
(or else, directly add the size='5' inline code in input attributes in the body section.)
<script async src="//jsfiddle.net/tX3ae/embed/"></script>
Bootstrap 3 I achieved a nice responsive form layout using the following:
<div class="row">
<div class="form-group col-sm-4">
<label for=""> Date</label>
<input type="date" class="form-control" id="date" name="date" placeholder=" date">
</div>
<div class="form-group col-sm-4">
<label for="hours">Hours</label>
<input type="" class="form-control" id="hours" name="hours" placeholder="Total hours">
</div>
</div>

How to put two inline input field correctly with Twitter Bootstrap?

I do the following at <div class="offset3 span6"> with bootstrap-responsive.css:
<div class="control-group">
<label class="control-label" for="passport1">Series and passport number</label>
<div class="controls">
<input type="text" class="input-small inline" id="passport1" placeholder="" maxlength="4">
<input type="text" class="input-medium inline" id="passport2" placeholder="" maxlength="6">
<p class="help-block">Please input your passport details into two fields above</div>
</div>
</div>
But text label is not aligned with input fields (it is lower). How to fix it?
demo
You have a top padding on your label of 5px;
Consider overriding this inline or creating a more specific css selector and try again.

Resources