Bootstrap 3.0: How to have text and input on same line?

后端 未结 10 929
忘掉有多难
忘掉有多难 2021-01-30 10:10

I\'m currently switching my website over to Bootstrap 3.0. I\'m having an issue with form input and text formatting. What worked in Bootstrap 2 does not work in Bootstrap 3.

相关标签:
10条回答
  • 2021-01-30 10:38

    You can do it like this:

    <form class="form-horizontal" role="form">
        <div class="form-group">
            <label for="inputType" class="col-sm-2 control-label">Label</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" id="input" placeholder="Input text">
            </div>
        </div>
    </form>
    

    Fiddle

    0 讨论(0)
  • 2021-01-30 10:42

    Or you can do this:

    <table>
      <tr>
        <td><b>Return:</b></td>
        <td><input id="return1" name='return1' 
                  class=" input input-sm" style="width:150px"
                  type="text" value='8/28/2013'></td>
      </tr>
    </table>
    

    I tried every one of the suggestions above and none of them worked. I don't want to pick a fixed number of columns in the 12 column grid. I want the prompt, and the input right after it, and I want the columns to stretch as needed.

    Yes, I know, that is against what bootstrap is all about. And you should NEVER use a table. Because DIV is so much better than tables. But the problem is that tables, rows, and cells actually WORK.

    YES - I REALLY DO know that there are CSS zealots, and the knee-jerk reaction is never never never use TABLE, TR, and TD. Yes, I do know that DIV class="table" with DIV class="row" and DIV class="cell" is much much better. Except when it doesn't work, and there are many cases. I don't believe that people should blindly ignore those situations. There are times that the TABLE/TR/TD will work just fine, and there is not reason to use a more complicated and more fragile approach just because it is considered more elegant. A developer should understand what the benefits of the various approaches are, and the tradeoffs, and there is no absolute rule that DIVs are better.

    "Case in point - based on this discussion I converted a few existing tds and trs to divs. 45 minutes messing about with it trying to get everything to line up next to each other and I gave up. TDs back in 10 seconds later - works - straight away - on all browsers, nothing more to do. Please try to make me understand - what possible justification do you have for wanting me to do it any other way!" See [https://stackoverflow.com/a/4278073/1758051]

    And this: "

    Layout should be easy. The fact that there are articles written on how to achieve a dynamic three column layout with header and footer in CSS shows that it is a poor layout system. Of course you can get it to work, but there are literally hundreds of articles online about how to do it. There are pretty much no such articles for a similar layout with tables because it's patently obvious. No matter what you say against tables and in favor of CSS, this one fact undoes it all: a basic three column layout in CSS is often called "The Holy Grail"." [https://stackoverflow.com/a/4964107/1758051]

    I have yet to see a way to force DIVs to always line up in a column in all situations. I keep getting shown trivial examples that don't really run into the problems. "Responsive" is about providing a way that they will not always line up in a column. However, if you really want a column, you can waste hours trying to get DIV to work. Sometimes, you need to use appropriate technology no matter what the zealots say.

    0 讨论(0)
  • 2021-01-30 10:46

    In Bootstrap 4 for Horizontal element you can use .row with .col-*-* classes to specify the width of your labels and controls. see this link.

    And if you want to display a series of labels, form controls, and buttons on a single horizontal row you can use .form-inline for more info this link

    0 讨论(0)
  • 2021-01-30 10:47

    just give mother of div "class="col-lg-12""

    <div class="form-group">
    <div class="row">
        <div class="col-xs-3">
            <label for="class_type"><h2><span class=" label label-primary">Class Type</span></h2></label>
        </div>
        <div class="col-xs-2">
            <select name="class_type" id="class_type" class="  form-control input-lg" style="width:200px" autocomplete="off">
                <option >Economy</option>
                <option >Premium Economy</option>
                <option >Club World</option>
                <option >First Class</option>
            </select>
        </div>
     </div>
    

    it will be

    <div class="form-group">
    <div class="col-lg-12">
      <div class="row">
        <div class="col-xs-3">
            <label for="class_type"><h2><span class=" label label-primary">Class Type</span></h2></label>
        </div>
        <div class="col-xs-2">
            <select name="class_type" id="class_type" class="  form-control input-lg" style="width:200px" autocomplete="off">
                <option >Economy</option>
                <option >Premium Economy</option>
                <option >Club World</option>
                <option >First Class</option>
            </select>
        </div>
    </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题