Style form-inline does not work on all the elements - html

Here is my partial bootstrap code. The form lets you search a person by first name and last name:
<div style="text-align:right">
<div class="form-inline">
<div class="form-group">
<label for="Search">Search</label>
</div>
<div class="form-group">
<input class="form-control text-box single-line" id="FirstName" name="FirstName" placeholder="First Name" type="text" value="" />
</div>
<div class="form-group">
<input class="form-control text-box single-line" id="LastName" name="LastName" placeholder="Last Name" type="text" value="" />
</div>
<div class="form-group">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</div>
The topmost div helps the set of inner controls to be shown on the right side of the web page (as desired).
When the viewport is wide enough, all the controls are displayed in one line as they are supposed to be.
However, when the viewport width is reduced, the text-box controls line up vertically (as expected) but the "Search" label and the "search" button stay on the right of the page.
Why are some elements aligning vertically while some others are not?
This does not happen if I remove the topmost div. However, I do need it to display the controls on the right side of the page.
I am wondering if there is a way to make all the controls in the set work consistently. Regards.

Use the * selector to choose all elements within the div form-inline
.form-inline *
{
/* Desired style here */
}

Best way to do it is by using the * selector, this says that the style will be applied to all the elements within the div class form-inline
.form-inline *
{
/* Place your styling stuff here */
}

Setting left-align style on label as well as the button solved my problem:
<div class="form-group" style="text-align:right">
<label for="Search">Search</label>
</div>
Now, when the viewport is wide enough, all the elements are shown in one line on the right side of the view port. When the viewport reduces in width, all the controls are shown vertically as left-aligned.

Related

Make input fill the entire free space in navbar

Here is how my navbar should look:
As you can see there is a logo, loop icon, clear icon and input field that takes all the space between those two icons (no matter what resolution).
Here is how my navbar looks now:
I have tried several different aproches to fill the empty space with input without breaking responsive features, but I have failed.
How can I make input field fill the entire space between these two icons on every screen?
Here is plunker
Can you replace your form with
<form class="navbar-form">
<div class="form-group" style="display:inline;">
<div class="input-group" style="display:table;">
<span class="input-group-addon" style="width:1%;"><span class="glyphicon glyphicon-search"></span></span>
<input class="form-control" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus" type="text">
<span class="input-group-addon" style="width:1%;"><span class="glyphicon glyphicon-remove"></span></span>
</div>
</div>
</form>
I hope it helps.

How do I set a default size for a textarea, yet still allow it to adjust based on the user's device?

I am trying to make a textarea with 5 rows and a width defaulted to the width of the container below it, but also allow it to become more narrow if a user is on a small mobile device (e.g. a smart phone). I've been researching and I see that there is debate on whether to use CSS or HTML to alter the size of a textarea. I'm fairly new to web development (started last week), so if you know how to fix my problem could you tell me why you chose the method you did?
<form class="form-inline">
<div class="form-group">
<textarea class="form-control" rows="5"></textarea>
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
<div class="input-group">
<div class="input-group-addon">$</div>
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
</div>
</div>
<button type="submit" class="btn btn-primary">Send!</button>
</form>
using form-inline makes the form-group display inline-block.. if you want the form-group to stretch the entire width you can use form-horzontal
or you can just set the display style of the form-group to block
<form class="form-inline">
<div class="form-group" style="display:block">
<textarea class="form-control" rows="5"></textarea>
</div>
</form>
make sure you site.css doesn't have a max-width value for textareas. this is in the default style sheet I believe
input,
select,
textarea {
max-width: 280px;
}

Content must be in column, but form label isn't?

In my form I've got fields with labels and fields without a label (i.e. a large textarea). I've given both my label and input fields a background color. Currently, the left margin of the labels differs from the left margin of the input fields.
The documentation says:
Content should be placed within columns, and only columns may be
immediate children of rows.
But the horizontal form example puts a <label> element inside a column:
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
The <label> element is a column, but it is content itself as well:
An easy way to have the same left margin for labels and inputs is to put the label inside a column, instead of being a column as well. Is that the best solution, or is there another way to have both labels and inputs have the same left margin?
What the documentation says:
Content should be placed within columns, and only columns may be
immediate children of rows.
It has to be interpreted in context of row. It means you don't put content directly in a row but use columns to layout the content. This is because, bootstrap adds a standard 15px padding on columns (first and last offsetted) to do a clean layout.
Further down the documentation says this:
Columns create gutters (gaps between column content) via padding. That
padding is offset in rows for the first and last column via negative
margin on .rows
Note: Now this padding is important in your use-case.
It doesn't really matter if you style your labels with col-xx- classes or wrap them in a div and apply col-xx- class to the wrapping div. Net effect of layout remains same.
You have provided a background-color for your labels and which is exactly why you are seeing a difference. See, when there is a label with col-xx- style applied, it behaves like a bootstrap column i.e. it gets 15px padding. So the label-text starts at 15px padding even though the label itself starts at the edge. However, when you wrap your label in a div and apply col-xx- style to the wrapping div, then this div gets the padding and the label starts after this padding.
This difference is what is manifesting itself visibly in your design.
This snippet will make it clearer: (Notice the "Email" label which is a label with col-xx- i.e. label styled as bootstrap column. The "Password" label however is wrapped inside a div which as col-xx- style applied. Notice the difference due to padding.)
div.form-horizontal { border: 1px solid gray; }
textarea { width: 100%; }
label { background-color: silver; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<br/><br/>
<div class="row">
<div class="form-horizontal col-xs-offset-2 col-xs-8 ">
<div class="form-group">
<label class="col-xs-12">Definitie</label>
<div class="col-xs-12">
<textarea></textarea>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-xs-2 control-label">Email</label>
<div class="col-xs-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email" />
</div>
</div>
<div class="form-group">
<div class="col-xs-2">
<label for="inputPassword3" class="control-label">Password</label>
</div>
<div class="col-xs-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password" />
</div>
</div>
</div>
</div>
Here is a fiddle for you to play with: http://jsfiddle.net/abhitalks/gkkwevnz/
.

HTML Content Not Centering on Narrow Screens

I am using Bootstrap 3, and coding mainly for mobile websites. I am having trouble centering content when I don't want it to take up the whole line. When the screen is larger than a certain width, it doesn't get centered, & when it is smaller than that width (especially at the size we are optimizing it for), it won't even come away from the left border of the page. Also, some elements keep jumping in size when they get to be a certain size. I assume that last one is normal behavior, but can't for the life of me figure out why.
HTML:
<div class="col-xs-12">
<div class="container">
<div class="form-group col-xs-11">
<div class="col-xs-5 pull-left">
<input type="text" class='form-control' id="firstName" name="firstName" placeholder="First Name" required />
</div>
<div class="col-xs-5 pull-right">
<input type="text" class='form-control' id="lastName" name="lastName" placeholder="Last Name" required />
</div>
</div>
</div>
<div class="form-group">
<input type="email" class='form-control' id="email" name="email" placeholder="Email" required />
</div>
</div>
The #media's in bootstrap-custom.css are:
#media (min-width 1200)
.container {
max-width: 1140px;
}
#media (min-width 992)
.container {
max-width: 940px;
}
#media (min-width 768)
.container {
max-width: 720px;
}
.container {
margin-right: auto;
margin-left: auto;
padding-left: 0;
padding-right: 0;
}
I'm not sure if that's the right/accepted way to quote them.
I also have the rest of the bootstrap-custom.css, if you need that for your answer.
P.S. The whole reason I didn't have the first row (with firstName & lastName) take up the whole line is because I don't want it to. I wanted that row to be in the middle with space on either side.
P.P.S. Here is a fiddle.
Disclaimer: I haven't done any Bootstrap before - I'm just stabbing in the dark.
For a simple two column layout, create a .row and add the appropriate number of .span* columns. As this is a 12-column grid, each .span* spans a number of those 12 columns, and should always add up to 12 for each row (or the number of columns in the parent).
So, I changed your col-xs-5 elements to col-xs-6 so that they would add up to twelve, and therefore take up 100% of the row's width together. I moved your email input field into the .container and added the col-xs-11 class in order for it to mirror the other form-group's left and right margin. I wrapped your email input field in a div (as you had done with the other fields), and added the col-xs-12 class to make it stretch to 100% of its parent row's width.
Here is a fiddle.
Also, some elements keep jumping in size when they get to be a certain
size. I assume that last one is normal behavior, but can't for the
life of me figure out why.
Here is an updated fiddle that employs CSS3 transitions to ease between your different max-widths.
Have you tried text-align:centre; to your container class?
I think you need to change your markup a little. Wrap everything inside a container and make your form-group as rows..
For example:
<div class="container">
<div class="col-xs-12">
<div class="row form-group">
<div class="col-xs-6">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name" required="">
</div>
<div class="col-xs-6 pull-right">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name" required="">
</div>
</div>
<div class="row form-group">
<div class="col-xs-12">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" required="">
</div>
</div>
</div>
</div>
Working demo: http://bootply.com/86294
P.S. - Take a look at Option #2 in the demo so that your inputs don't get too small. This will allow them to stack vertically on the smallest screens.

How to push an html element to right, as the previous element grows in width dynamically?

I have two input textbox that grows dynamically based on the size of the input. In between that there is a small text. The problem is that when the textbox grows in width, it overlaps the text next to it.
I am looking for an HTML/CSS styling that lets me push the text to right side as the textbox grows in width.
Any help is greatly appreciated.
Thanks
Adding some of my code.
.dynamic-push {
float: left;
}
<div class="row dynamic-push">
<div class="two columns dynamic-push ">
<input id="contact-position" class="dynamic-push" value="" type="text" placeholder="Position" data-bind="value: Person().Position, valueUpdate: 'afterkeydown', afterRender: $('#contact-position').autosizeInput()" /> at
<input id="contact-company" value="" type="text" placeholder="Company" data-bind="value: Person().Company, valueUpdate: 'afterkeydown', afterRender: $('#contact-company').autosizeInput()" />
</div>
</div>
There are knockout elements and I have used jquery autosize.input.js plugin to increase the width of the input text box dynamically.
Now the 'at' between the two input textboxes is being overlapped by the first textbox as it grows.
Hope you can figure out what is wrong here. If you need any other CSS codes, I'll share those too
Why not simple float them left within a container:
ONLINE DEMO
(demo contains animation enlarging the textbox)
HTML:
<div>
<input><div>Box 1</div<div>Box 2</div
</div>
CSS:
div > input,
div > div {
float:left;
}
(of course exchange div with a proper class).
Update
Thanks to OP for providing more code.
However, as you can see in this modified fiddle:
http://jsfiddle.net/AbdiasSoftware/LxByQ/2/
the problem is not at DOM level as the boxes pushes and moves as expected.
The problem is most likely in the autosizeInput function which deals with the chars and so forth. The delay can be caused by how it handles this. As the code for it isn't shown it's hard to locate exact reason but this is where you want to look in first instance.
Depends on how that automatic resize function handles it. If it adjusts the width of the first input field, you can try flexbox:
<div class="row dynamic-push">
<div class="two columns dynamic-push mylittleflexcontainer">
<input id="contact-position" class="dynamic-push" value="" type="text" placeholder="Position" data-bind="value: Person().Position, valueUpdate: 'afterkeydown', afterRender: $('#contact-position').autosizeInput()" />
<span> at</span>
<input id="contact-company" value="" type="text" placeholder="Company" data-bind="value: Person().Company, valueUpdate: 'afterkeydown', afterRender: $('#contact-company').autosizeInput()" />
</div>
</div>
.mylittleflexcontainer {
display: flex;
}
.mylittleflexcontainer:first-child {
flex-grow: 1;
}