Forcing label to flow inline with input that they label

前端 未结 7 1205
时光取名叫无心
时光取名叫无心 2020-12-13 17:55

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 t

相关标签:
7条回答
  • 2020-12-13 18:16

    What I did so that input didn't take up the whole line, and be able to place the input in a paragraph, I used a span tag and display to inline-block

    html:

    <span>cluster:
            <input class="short-input" type="text" name="cluster">
    </span>
    

    css:

    span{display: inline-block;}
    
    0 讨论(0)
  • 2020-12-13 18:16

    Why don't You just use:

    label {
        display: block;
        width: 50px;
        height: 24px;
        float: left;
    }
    
    0 讨论(0)
  • 2020-12-13 18:19

    Put the input in the label, and ditch the for attribute

    <label>
      label1:
      <input type="text" id="id1" name="whatever" />
    </label>
    

    But of course, what if you want to style the text? Just use a span.

    <label id="id1">
      <span>label1:</span>
      <input type="text" name="whatever" />
    </label>
    
    0 讨论(0)
  • If you want they to be paragraph, then use it.

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

    Both <label> and <input> are paragraph and flow content so you can insert as paragraph elements and as block elements.

    0 讨论(0)
  • 2020-12-13 18:34

    put them both inside a div with nowrap.

    <div style="white-space:nowrap">
        <label for="id1">label1:</label>
        <input type="text" id="id1"/>
    </div>
    
    0 讨论(0)
  • 2020-12-13 18:34
    <style>
    .nowrap {
        white-space: nowrap;
    }
    </style>
    
    ...
    
    <label for="id1" class="nowrap">label1:
        <input type="text" id="id1"/>
    </label>
    

    Wrap your inputs within the label tag

    0 讨论(0)
提交回复
热议问题