Bootstrap 3 an fix the border radius for an input with three input groups - html

Consider below html code, which uses bootstrap 3 input group to create an input three input groups.
<h1>border radius</h1>
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon">
<input value="false" type="radio"/>
</span>
<div class="input-group">
<span class="input-group-addon">*</span>
<input type="text" class="form-control"/>
<span class="input-group-addon">?</span>
</div>
</div>
</div>
The default bootstrap style puts border radius for all input groups, which is not good for the middle input groups (I mean the tiny left radius around * ).
To remove this radius, I try to set the border radius for all input groups to zero except the last one.
div.input-group > div.input-group > span.input-group-addon:not:last-child{
border-radius: 0px !important;
}
But it did not work !
Please let me know what is wrong with this selector, and if I can do it easier !
fiddle : http://jsfiddle.net/mtamx8bs/

:not() is a functional pseudo-class so it needs parentheses around its argument:
div.input-group > div.input-group > span.input-group-addon:not(:last-child)
And on that note I removed the !important as it's no longer needed now that I've fixed the selector.

Due to the way that Bootstrap applies the rounded border styling to the .input-group-addon class, only the first and last "addon" within an .input-group will end up with rounded corners.
Based on this, I'd suggest you consider wrapping all your required elements in a single input group, rather than trying to nest one inside the other.
For example:
<div class="input-group">
<span class="input-group-addon"><input value="false" type="radio"/></span>
<span class="input-group-addon">*</span>
<input type="text" class="form-control" />
<span class="input-group-addon">?</span>
</div>
I updated your fiddle with these changes if you want to play with it. (Edit: or check this one for a slightly more verbose version, showing how much cleaner the code looks with multiple groups)
As an extra note: there are some cases where you may end up nesting different types of "group" classes from Bootstrap, but you'll probably need to play with them to work out which combinations will achieve exactly what you want.
This page in the docs shows an example of two button elements (normal button and a drop-down button) inside an .input-group-btn class, which is nested inside an .input-group.

Related

Split text input to few cells using CSS

I need to split input to few cells. I want to draw few blocks and in each user press, one of the blocks will fill. Something like this:
What is the right way to do it?
This is the code of the form:
<div class="wrap-log-in-form" *ngIf="step == 'pass'">
<input type="text" class="spliting-input" maxlength="6">
<div class="buttens-log-in">
<input type="button" value="אמת">
<input type="button" value="קבל הודעה בטלפון">
</div>
</div>
You can use a CSS background image on the input and try to use letter-spacing to get the text to fall in the correct areas, BUT this is really hard and not a great solution.
The issue is each device and browser displays characters slightly differently so the spacing is always off just a bit. This is pretty hacky but works if you only have access to the CSS.
A better solution
Use Javascript to parse the input and split each character into its own element with unique placement and background styling.

Input field with label in semantic-ui breaks layout

I am trying to make an input field with a (right-aligned) label in semantic ui. The documentation shows an example of a cornered label that works fine (http://semantic-ui.com/elements/input.html) , but when I try to use a plain label it breaks the layout of the input field
I made a fiddle that explains my attempt (http://jsfiddle.net/26fqd39d/ ).
The following code works fine (taken from the documentation): It shows an input field with a label on the right which fits in the layout of the input field.
<div class="ui labeled input">
<input type="text" value="#"></input>
<div class="ui corner label"><i class="copy icon"></i></div>
</div>
I don't want to use a cornered label though, since there is not enough room for my scenario (I would like to display some units in this label, like km, mi, etc).
I change it to use a regular label:
<div class="ui labeled input">
<input type="text" value="#"></input>
<div class="ui label"><i class="copy icon"></i></div>
</div>
As you can see in the fiddle, the label breaks on the new line.
How can I create an input field with a right-aligned label using semantic-ui ? An explanation of why this doesn't work will also help me understand how to build layouts using semantic-ui.
Thanks.
I played around a bit and found a work-around that uses right (or left) aligned icons instead of labels. Hope this helps.
<div class="ui right icon input">
<input type="text" placeholder="Copy copy copy">
<div class="icon"><i class="copy icon"></i></div>
</div>
http://jsfiddle.net/12pjjrp7/4/
I'm not quite familiar with Semantic but you could keep your corner class and override the right borders like so:
.ui.action.input > .button {
border-top-right-radius: 0px !important;
border-bottom-right-radius: 0px !important;
}
Use !important as it should be overriding the current style and don't forget to be specific with your class selector (so it only affects the buttons you want to). or use a style attribute.

Is there a more efficient way to group-up a label with an input field so that they become block-like?

I want to make a HTML form for a webpage that is re-size-able ranging form full HD to smartphones. I want the distance form the label to the input to be the same distance such that if the form was to be placed in a div that for instance is 600px and the label and input field as line totals to 300px (including padding,margin, etc) that the fields order in 2 columns. If the div than after re-size would become 900px the form would spread over 3 columns.
The fields should then be ordered in the following manner:
with 2 columns:
F1 F4
F2 F5
F3 F6
with 3 columns:
F1 F3 F5
F2 F4 F6
Now since i am relatively new to HTML and CSS i personally would do this with a lot of div's but that seems a little bit redundant or just as really bad coding. I tried to do this with a <span style="width:300px;"> but the span wont be 300 px nor will it include the input field.
my current form:
<div class='main_text' style='width:55%;padding-left:10%;padding-right:10%;'>
<label>Name:</label>
<input id="name" type="text" value='Name'/><br />
Age:
<input id="age" type="text" value='21'/><br />
Insterests:
<input id="interests" type="text" value='Socer'/><br />
Targets:
<input id="targets" type="text" value='stop smoking for at least 2 years'/><br/>
Other:
<input id="other" type="text" value='I have 3 cats'/><br />
</div>
So the question in short is:
Is there a more efficient way to group-up a label with an input field so that they become block-like?
P.S. Im using XHTML 1.0 transitional
I suggest taking a look at existing frameworks like Bootstrap or Foundation that will provide you with a good base to start writing a responsive design.
For the record, a span is an inline element hence you cannot define a width on it. Declare it as display: inline-block; and you'll notice the width property is now respected.
It's common to see radio buttons and checkboxes element tuples wrapped from the label, like this:
<label> <input /> text </label>
However you will find more and better examples on bootstrap.
First of all: use the <label>´s "for"-attribute to link the label to the input-field:
<label for="name">Name:</label>
<input id="name" type="text" value='Name'/><br />
And then, no: if you want to "group them together", in a box with borders for example, the best is to use div. That´s my opinion.
EDIT:
I´m not that good at reading the whole question before I answer.
I agree that you should take a look at a responsive framework if you want to make things easier for you when you create web pages that should look great on mobile as well as desktop.
Twitter bootstrap is one: http://twitter.github.io/bootstrap/
Foundation is another: http://foundation.zurb.com/
Find one you like and try it out. Personally, I like Bootstrap the most.

Size of select box in Twitter Bootstrap

I'm using Twitter Bootstrap. Select boxes are always narrower than input boxes.
How can I make them the same width? Adding padding helps, but it looks ugly.
EDIT
Here is a little example - http://jsfiddle.net/DfY8z/2/
Same example with custom class applied - http://jsfiddle.net/DfY8z/3/
I can use classes like span3, span4 etc. But I want my inputs to fill all available space (and to be the same size) so I'm using custom class.
Just adding input-sm class just next to the form-control worked for me.
<select class="form-control input-sm" id="xxx" ... >
<input type="text" value="" name=""><br>
<select>
<option>Some options which is very very long... </option>
</select>
The result is the exact size of the boxes.
You appear to be using an older version of bootstrap (current version is 2.2.1). Select boxes and input boxes in newer versions are the same size when no class is applied and when resized using the span* method
If you need to set a custom size you will have to use 2 different custom classes or target select boxes and input boxes individually. The input boxes need to be 14px smaller than select boxes (as do text areas).
See updated example
// code sample because its required
<input class="myClass" type="text" value="Abcdefghijklmnop" />
<br />
<br />
<select class="myClass">
<option> ABC </option>
<option> XYZ </option>
</select>
place the control
inside a div and apply class="col-sm-2" on the div.
<div class="col-sm-2">
<select></select>
you can change col-sm-2 col-sm-3 as per your requirement
This has worked for me -
Go to bootstrap.css file and comment out the following --
select.form-control:not([size]):not([multiple]) {
height: calc(2.25rem + 2px); }
This works:
<select style="width: 200px">...</select>

Best way to layout in HTML forms?

I want to display an HTML form containing labelled text fields, like this:
First Name: [_____________]
Last Name: [_____________]
Date of Birth: [________]
My obvious approach is to use a <TABLE> and simply place the labels and text fields in its cells, but is there a better way, e.g. a CSS-based approach?
EDIT:
I'm looking for a way that reduces the verbosity in the HTML file.
And yes, I'm looking for auto-sizing of the labels. See a related question about wrapping labels
If you need the labels to the left of the fields like that, just go ahead and use a table. Not only do tables degrade nicely on older browsers, but they auto-size the column of labels to the text in them (assuming you use white-space: no-wrap on the cells containing the labels, and/or — and this is true heresy — the trusty old nowrap attribute on the th tag), they handle being made fairly narrow well, and they're easy. Make each label cell a header and each field cell a normal cell. And it's a pain, but make sure the labels really are labels and link to their fields, because accessibility matters, even if (perhaps especially if) you're using a table non-semantically.
I'd love to hear about CSS solutions that auto-size the label columns, handle being narrow well, and don't involve 18 hacks to deal with inconsistencies across browsers. I'd be thrilled to see them. But every time I've looked (and that's several), it's still been a gap. A gap that needs filling, IMV, so we can stop doing this without wearing hairshirts.
For anyone reading who doesn't need the labels to the left like that, check out jball's answer for a good-looking, semantic alternative.
In terms of usability and if vertical space is not a limiting factor, a list of fields with the label above each field is the quickest to read and fill out, and can be done aesthetically. See many of the usability studies on the web for more info, eg. http://www.lukew.com/resources/articles/web_forms.html
I'd like to use definition lists (<dl>) they tends to be semantically correct.
A label is defined by an user input. It has sense to me.
<dl> expresses semantic contents more accurately than a table.
<dl>
<dt><label for="name>Name</label></dt>
<dd><input type="text" id="name" /></dd>
<dt><label for="email>Email</label></dt>
<dd><input type="text" id="email" /></dd>
</dl>
Here is an example
By the way they degrade gracefully in all browser, even text-based.
I think something like this is what i do but also won't autosize to the length of the text but it's cleaner in my opinion
<form>
<label for="firstName">First Name</label>
<input type="textfield" name="firstName" />
<label for="lastName">Last Name</label>
<input type="textfield" name="lastName" />
</form>
label {
float:left;
width:30px;
}
input {
float:left;
margin-left:30px;
}
The article is a bit old, but I've always found a list apart's advice to be solid: (if you do want to get rid of your tables)
http://www.alistapart.com/articles/prettyaccessibleforms/
CSS Table Display
From IE8+ you can use CSS Table Display for this:
<!DOCTYPE html>
<html>
<head>
<style>
form > div > label { text-align: right; vertical-align: top }
form { display: table; }
form > div { display: table-row; }
form > div > label,
form > div > textarea,
form > div > input { display: table-cell; }
</style>
</head>
<body>
<form method="post">
<div>
<label for="name">Name</label>
<input type="text" id="name" size="14"/>
</div>
<div>
<label for="message">Message</label>
<textarea id="message"></textarea>
</div>
<div>
<label for="ssn">Social Security Number</label>
<input type="text" id="ssn"/>
</div>
<div>
<label></label>
<input type="submit" value="Send"/>
</div>
</form>
</body>
</html>
Use a CSS framework like Blueprint and use that to style the forms.
Another trick would be to create virual "columns" with css and float them next to each other. Labels in one column and inputs in another. Put that (both columns) in a div with a large enough width and float the columns the opposite way you want to align them.
Here's some code (because I am creating a form) that will work for basic forms. The only constraint is the large right margin on inputs.
form input, form select
{
float: right;
margin-right: 650px;
}
form label
{
float: right;
margin-top: 5px;
margin-right: 10px;
}
form .nofloat
{
float: none;
margin: 0;
}
form br
{
clear: both;
}
And layout like so
<input type="text" id="name" />
<label for="name">Name</label>
<br />
On top of this small, narrowly written code, there is an entire article related to creating tableless forms in CSS.
Typically, I have found that there are at least some issues when not using Tables for forms. The general things I have not been able to solve:
Background-color for fields/inputs is not really possible without a faux background
Auto-sizing columns, but I think this is OK
Field hover with CSS, you could use JS but Tables can do this with pure CSS
I might be missing a few things, but the most flexible mark-up if you are using CSS is as below:
<div class='form-field'>
<label>Name</label>
<input />
</div>
You have issues if you want multiple fields per label section, so you have to introduce another div to hold the inputs (to allow the label to still float left etc):
<div class='form-field'>
<label>Name</label>
<div class='form-inputs'>
<input />
<input />
</div>
</div>
With the above mark-up you can achieve very flexible forms, I won't post the CSS as it's very similar to a 2 Column-Layout.
I still need to sit down and try and figure out if pure CSS forms are viable for all occasions but tbh it's very unlikely!
Forms are the worst thing to style using CSS. The only major Cross Browser problems i've had are when styling the FieldSet and Legend elements. No real hacks, but they take some work to look good.
One problem with tables is the space bug. When you don't use tables you can write your label and input like this:
<label for="foo">Blah <input id="foo" type="text"/></label>
which properly encapsulates the input and the label.
In a table, on the other hand, you get those separated:
<td><label for="foo">Blah</label></td><td><input id="foo" type="text"/></td>
That means the area between the </label> and the <input/> does not respond to mouse clicks.
It's not too bad with plain fields, it's really annoying with radio buttons and checkboxes though (or maybe I'm just being super picky.)
Now, to answer your question: I don't think there is a good way to do formatting of a column in CSS (unless the column width is known--you could obtain that feat with JavaScript...) So T.J. Crowder certainly has an excellent answer.
However, there's one argument for CSS (and forced widths) as in one case I created a very large form that covered the whole screen. All the fields would appear in one screen (As the customer wanted) and the CMS did not output a table. But even though, a table would have been a nightmare simply because all the fields were for many placed in non-aligned columns. That would be quite difficult with a table (lots of rowspan using the table as a grid which would be a table for layout!).
Update:
As per comment below, singe31 says that <input/> cannot be defined within the <label> tag. This is wrong. The HTML 4.01 DTD is easy to read and we see that:
<!ELEMENT LABEL - - (%inline;)* -(LABEL) -- form field label text -->
<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">
<!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">
So in other words an <input/> can appear in a <label> tag. It is perfectly legal.
HTML 5 clearly shows that this is legal in the documentation on w3c here:
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-label-element
Scroll down a bit up to the "Code Example" and you see:
Code Example
For example, on platforms where clicking or pressing a checkbox label checks the checkbox, clicking or pressing the label in the following snippet could trigger the user agent to run synthetic click activation steps on the input element, as if the element itself had been triggered by the user:
<label><input type=checkbox name=lost> Lost</label>
On other platforms, the behavior might be just to focus the control, or do nothing.