6

I am a first-try bootstrap guy. The thing i want to achieve is to have labels and inputs same line nice and clean.

Anyone can explain me why in the below example labels are still above inputs? Am i doing something wrong?

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta application-name="Test-System">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

    <!-- Bootstrap Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

    <!-- jQuery UI from Google CDN -->
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
    <title></title>
</head>
<body>

    <form class="form-horizontal">
        <div class="control-group">
            <label for="input1" class="control-label">Label</label>
            <div class="controls">
                <input id="input1" type="text">
            </div>
        </div>

        <div class="control-group">
            <label for="input2" class="control-label">Label</label>
            <div class="controls">
                <input id="input2" type="text">
            </div>
        </div>
    </form>

     <!-- jQuery from Google CDN -->
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
     <!-- jQuery UI from Google CDN -->
     <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</body>
</html>
madth3
  • 7,275
  • 12
  • 50
  • 74
Stefanos Vakirtzis
  • 448
  • 1
  • 7
  • 19

1 Answers1

8
<div class="controls">
                <label for="input1" class="control-label">Label</label>
                <input id="input1" type="text">
 </div>

Is this what you are looking for?

EDIT Horizontal label from outside of input's div.

    <div class="control-group">
        <label for="input1" class="control-label col-sm-2">Label</label>
        <div class="controls col-sm-10">
            <input id="input1" type="text">
        </div>
    </div>
Chris
  • 3,405
  • 4
  • 29
  • 34
  • Well indeed thats what i was looking for thanks a lot. But in order not to seem so stupid, was i doing something wrong above? Cause i ve seen many ppl use labels outside controls div and still have the one line effect. – Stefanos Vakirtzis Feb 18 '14 at 19:28
  • 1
    @StefanosVakirtzis It seems that horizontal display is made with `col-sm-2` and `col-sm-10` – Chris Feb 18 '14 at 19:37
  • Hmm this doesn't seem to work for me when I attempt to wrap the control in a label `` Any tips? – Kevin Friedheim Oct 26 '15 at 19:28