Using CSS for a multiple-column form - css

any suggestions on the best way to do a form like that? http://i.imgur.com/vT7tC.png
I'm using tables + input with width: 100%, I know it's probably not the best way
(also, for some reason the input width: 100% gets bigger than [td] or [div] (the red border on this image is from a [div][input ...][/div])
thanks

You can float the left label/inputs to the left and the right label/input to the right.
You will need to specify a width otherwise you will end up with a large gap between your columns and your middle column will not line up with your large right input.
This is how I would code that form:
HTML
<div class="content">
<div class="row">
<div class="lrow">
<label>aaa aaa</label>
<input type="text" class="large">
</div>
<div class="rrow">
<label>bbb</label>
<input type="text" class="small">
</div>
</div>
<div class="row">
<div class="lrow">
<label>ccc</label>
<input type="text" class="small">
</div>
<div class="rrow">
<label>ddd ddd</label>
<input type="text" class="large">
</div>
</div>
<div class="row">
<div class="lrow">
<label>eee</label>
<input type="text" class="small">
</div>
<div class="rrow">
<label>fff fff</label>
<input type="text" class="small">
</div>
<div class="crow">
<label>ggg</label>
<input type="text" class="small">
</div>
</div>
</div>
CSS
.content {width:542px;}
.row {overflow:hidden;margin:5px 0;}
.row label {float:left;text-align:right;width:60px;margin-right:5px;}
.row input {float:left;}
.lrow {float:left;}
.rrow {float:right}
.large {width:300px;}
.small {width:100px;}

don't waste your time by making columns by hand.
just use Blueprint CSS Framework. it's really nice and easy to use and does the job in a way you want.
the most important of all, you do not need to care about browser compatibility anymore.

Related

How do I align Bootstrap inline form labels that don't have an input with those that do?

When the content is wide enough to have this all on the same row without line breaking (probably need to go full page with the snippet), the right label text is aligned slightly higher than the left label text. I'm trying to get the text of the two labels aligned to the same baseline.
I've tried to use vertical align in various ways, tried to set the height the same as the left on the right group, but I can't get anything to work.
Of course I could just set a fixed margin, but is there a responsive way to do this?
.main {
margin-top: 20px;
}
#left-input {
width: 100px;
}
.vmiddle {
/* does nothing ? */
vertical-align: middle;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container main">
<div class="row">
<div class="col-xs-6 ">
<div class="form-inline">
<div class="form-group">
<label>Left Label:</label>
<input id="left-input" type="text" class="form-control" value="Some Value" />
</div>
</div>
</div>
<div class="col-xs-6 vmiddle">
<div class="form-inline">
<div class="form-group">
<label>Right Label: Higher</label>
</div>
</div>
</div>
</div>
</div>
Since the second one is technically not a label, you can use Bootstrap's Static form control instead. It's designed to align with form-control and .btn elements.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container main">
<div class="row">
<div class="col-xs-6 ">
<div class="form-inline">
<div class="form-group">
<label>Left Label:</label>
<input id="left-input" type="text" class="form-control" value="Some Value" />
</div>
</div>
</div>
<div class="col-xs-6 vmiddle">
<div class="form-inline">
<div class="form-group">
<p class="form-control-static"><strong>Right Label</strong></p>
</div>
</div>
</div>
</div>
</div>
Add a margin utility class that's half the height of Bootstrap's padding.
<style>
.m-t-7 {
margin-top: 7.5px;
}
</style>
<div class="col-xs-6">
<div class="form-inline">
<div class="form-group">
<label class="m-t-7">Right Label: Higher</label>
</div>
</div>
</div>
Yup.
First, give the right label an id so you can select it individually.
<label id="right">Right Label: Higher</label>
then, in your css add:
#right{
padding-top:2px; /*Insert your own value for paddin*/
}
and to make it dynamic, remove the padding when the left label stacks. Find the pixel width of the browser when this happens, and then create a media query for the event:
#media(max-width:300px){
#right{
padding-top:0;
}
}
Another idea which may not be possible in your layout, would be to limit the width of the content so it never gets wide enough for this.
Yes. Just try to remove the margin bottom of the <label>Right Label: Higher</label>. Please leave a comment if this wont work.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container main">
<div class="row">
<div class="col-xs-6 ">
<div class="form-inline">
<div class="form-group">
<label>Left Label:</label>
<input id="left-input" type="text" class="form-control" value="Some Value" />
</div>
</div>
</div>
<div class="col-xs-6 vmiddle">
<div class="form-inline">
<div class="form-group">
<label style="margin-bottom: 0;">Right Label: Higher</label>
</div>
</div>
</div>
</div>
</div>

RAILS: How to set width for a textarea in bootstrap 3 panel?

Here is a piece of erb code with a textarea. I used style="min-width: 100%" to make the area expanding to 100% width. But the style does not work at all.
<div class="container-fluid">
<div class="col-md-8">
<!--panel-->
<div class="panel panel-primary">
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-sm-<%=BUTTONS_CLS['left-span#']%> form-group">
<b><%=t('Batch#')%></b>
</div>
<div class="col-sm-<%=BUTTONS_CLS['right-span#']%> form-group">
<textarea class="form-control" rows="1" id="comment" style="min-width: 100%"><%= #part_production.requirement %></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here is the html source code of the textarea:
<div class="col-sm-5 form-group">
<textarea id="comment" class="form-control" rows="1" style="min-width: 100%"></textarea>
</div>
How to style the width of the textarea (percentage of the panel. without specifying certain px)?
use col-sm-12
like this
<div class="col-sm-12 form-group">
<textarea id="comment" class="form-control" rows="1" style="min-width: 100%"></textarea>
</div>
the reason maybe it won't get 100% percent is because of the col-sm-5 class.
You just check this code..
Try add min-width: 100% to style of your textarea:
<textarea class="form-control" style="min-width: 100%"></textarea>
otherwise try this..
<textarea class="form-control" rows="7"></textarea>
If you don't want to set style inline you can just add the css to your CSS files. 100% will expand to it's parents size.
textarea.form-control{ width: 100% !important; }
may be you want to consider to change your HTML markup to:
<div class="col-sm-5"><div class="form-group">...</div>...
instead of doing form-group and col in one div.

Bootstrap - Vertical Align Input Field

I am working on an app that uses Bootstrap 3. In this app, I have a row defined like this:
<div class="row" style="background-color:navy; color:white;">
<div class="col-lg-3">
<h2>Welcome</h2>
</div>
<div class="col-lg-8">
<form class="form-horizontal">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
find:
</div>
<input type="search" class="form-control" id="queryField" />
</div>
</div>
</form>
</div>
<div class="col-lg-1">
<button type="button" class="btn btn-primary">Go</button>
</div>
</div>
I want to make the search field and the Go button vertically aligned with the Welcome text. The Welcome text is kind of vertically aligned. I tried adding vertical-align: middle. That did not work. I was trying to avoid using padding. But if its required, its required. I appreciate any help you can provide.
There is default margin, padding in all tags, so put a class of
h2{ margin: 0; padding: 0; }
and it is automatically come in same line

Nesting Bootstrap input boxes side by side

I have two input boxes that I am trying to get side by side on the row but I'd like there still to be a gap between the boxes but flush to the sides of the container.
Is there a way using just Bootstrap to do this? The container is a replication of a mobile device.
<div class="group col-sm-12">
<div class="row">
<div class="col-sm-6">
<div class="row">
<input type="text" name="first-name" ng-model="user.firstname" />
</div>
</div>
<div class="col-sm-6">
<div class="row">
<input type="text" name="last-name" ng-model="user.surname" />
</div>
</div>
</div>
</div>
plunkr example
Bootstrap has a few different grid classes. col-<size>-<num> where <size> can be xs, sm, md, or lg, and <num> can be an integer between (and including) 1-12.
For mobile devices, you'll want to use xs. If you don't specify any of the larger sizes, then they'll use the same widths as the smaller one. If you change col-sm-12 to col-xs-12 and col-sm-6 to col-xs-6 I think you'll get the result you're looking for.
It also helps your inputs look more consistent and more easily themed if you give them the form-control class.
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="group col-xs-12">
<div class="row">
<div class="col-xs-6">
<div class="row">
<input class="form-control" type="text" name="first-name" />
</div>
</div>
<div class="col-xs-6">
<div class="row">
<input class="form-control" type="text" name="last-name" />
</div>
</div>
</div>
</div>
I'm not familiar with Bootstrap, but one way to achieve it would be to add this to your CSS:
.col-sm-6, .col-sm-6 .row, .col-sm-6 .row input {
display: inline-block;
}
I am not sure if I understand your question correctly. You need a space between the text box side by side right? if so try this code. You could also use col-xs-offset-1 for space between grid. This will allow you to push 1 grid away. example http://www.bootply.com/U6vlrIktq2
<div class="col-md-4">
<input type="text" class="form-control">
</div>
<div class="col-md-4 ">
<input type="text" class="form-control"><br>
</div>
<!-- for more spacing between boxes-->
<div class="col-xs-5">
<input type="text" class="form-control">
</div>
<div class="col-xs-5 col-xs-offset-1">
<input type="text" class="form-control">
</div>

bootstrap fluid grid: input breaks out of its container in ie7

Why in IE7 input breaks out of its container?
http://jsfiddle.net/Q8jPM/2/
<div class="row-fluid" style="margin-top:10px;">
<div class="span12">
<div class="row-fluid">
<div class="span6">
<div class="row-fluid">
<div class="span6 " style="background:green;">
<input type="text" class="span12">
</div>
<div class="span6" style="background:blue;">
<input type="text" class="span12">
</div>
</div>
</div>
<div class="span6">
<div class="row-fluid">
<div class="span6" style="background:green;">
<input type="text" class="span12">
</div>
<div class="span6" style="background:blue;">
<input type="text" class="span12">
</div>
</div>
</div>
</div>
</div>
</div>
​
UPDATE: I suppose it's box-model and width issue, but is any solution with bootstrap?
this happens because IE7 does not support the css property
box-sizing: border-box;
that considers padding and border size as part of the elements width.
read more about this property here: http://paulirish.com/2012/box-sizing-border-box-ftw/
because of this, IE7 adds the padding and border size to the input width - exceeding the parent width. You will have to set those to 0 in order to get the element fit to the parent size and stay fluid.
you could try adding a wrapper element around the input and then setting the padding and border to the wrapper. This will work in all browsers
I was having a similar issue. I resolved it by replacing
class="span3"
with
class="input-mini"
You could use input-small or whatever suits of course. Since you were looking for span12 for your inputs I'd suggest "input-xxlarge"

Resources