Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing label to flow inline with input that they label

Tags:

css

input

label

I need the label to stay on the same line as the input field they are labeling. I want these elements to flow like they normally would when the window resizes, i just want the label to stick to the left of the input they are labeling. How would I do that? Any ideas?

<label for="id1">label1:</label> <input type="text" id="id1"/> <label for="id2">label2:</label> <input type="text" id="id2"/> 

ANSWERED: Josiah Ruddell's answer was on the right path, using a span instead of div gave me the correct behavior. Thanks!

<span style="white-space:nowrap">     <label for="id1">label1:</label>     <input type="text" id="id1"/> </span> <span style="white-space:nowrap">     <label for="id2">label2:</label>     <input type="text" id="id2"/> </span> 
like image 931
user366735 Avatar asked Nov 17 '10 21:11

user366735


People also ask

How do you put an input element on the same line as its label?

Using table cell attribute in display property: Make a label inside a div and give the display property. To make the input element and span as equally placed use table-cell attribute in those tags. This attribute makes the element behaves a td element.

Are label tags inline?

According to the MDN pages, label elements "are simple inline elements".

How do you associate input labels?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit). Think of an implicit label as hugging an input, and an explicit label as standing next to an input and holding its hand.

Does HTML support inline style for label?

There are no special styling considerations for <label> elements — structurally they are simple inline elements, and so can be styled in much the same way as a <span> or <a> element. You can apply styling to them in any way you want, as long as you don't cause the text to become difficult to read.

How to force the label text to flow inline in CSS?

The following CSS class force the label text to flow inline and get clipped if its length is more than max-length of the label. .inline-label { white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; float:left; }

How to make an input element the same as its label?

There are several approaches to make an input element the same as its label. Few approaches are discussed here. Basic CSS to label, span, and input to get clear outputs. Using float and overflow attributes: Make a label and style it with float attribute. Now set the label float (position) left or right according to your requirement.

What is a floating label input field?

A floating label is a text label which appears inside the input field at full font-size. When interacted with, the label “floats” above, making room for the user to input a value. Building from scratch, you may look into the css pseudo classes: ::before and ::after.

Is our work finished on the label input field?

Our work isn’t finished. We need to think about all the use cases of this input field. Currently, the field returns the label back to it’s original position on ‘blur’. It doesn’t take into account if the input has a value. Our label will also currently overlap any placeholder text in the field.


1 Answers

put them both inside a div with nowrap.

<div style="white-space:nowrap">     <label for="id1">label1:</label>     <input type="text" id="id1"/> </div> 
like image 185
Josiah Ruddell Avatar answered Sep 21 '22 06:09

Josiah Ruddell