wax_lyrical
wax_lyrical

Reputation: 942

Bootstrap form not lining up correctly

Just starting out with Bootstrap. I want a form that lines up like the one on the w3 schools site: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_form_basic&stacked=h

However, mine doesn't line up.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
    <h2>foo View</h2>
    <form>
        <div class="form-group">
            <label for="fooName">Name:</label>
            <input class="form-group" id="fooName" type="text" value="fbdshfjdhk"/>
        </div>
        <div class="form-group">
            <label for="fooghk">ghk:</label>
            <input class="form-group" id="fooghk" type="text" value="fdsfdsfds"/>
        </div>
        <div class="form-group">
            <label for="fooXyz">Xyz:</label>
            <input class="form-group" id="fooXyz" type="text" value="ffdhfjhdsjk"/>
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
    </form>
</div>
</body
</html>

Upvotes: 1

Views: 360

Answers (2)

Hiren Jungi
Hiren Jungi

Reputation: 854

you should learn grid system properly in order to proper format the forms.

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Vertical (basic) Form</h2>
  <form>
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" class="form-control" id="email" placeholder="Enter email">
    </div>
    <div class="form-group">
      <label for="pwd">Password:</label>
      <input type="password" class="form-control" id="pwd" placeholder="Enter password">
    </div>
    <div class="checkbox">
      <label><input type="checkbox"> Remember me</label>
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
</div>

</body> 
</html>

Upvotes: 0

FreeKrishna
FreeKrishna

Reputation: 2093

Your form input tags should have the class "form-control" and not "form-group". It works well when corrected. Here is the working example--

<html>
    <head>
        <meta charset="UTF-8">
        <title>Secure Login: Protected Page</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
          </head>
          <body>

<div class="container">
    <h2>Product View</h2>
    <form>
        <div class="form-group">
            <label for="productName">Name:</label>
            <input class="form-control" id="productName" type="text" value="fbdshfjdh">
        </div>
        <div class="form-group">
            <label for="productDescription">Description:</label>
            <input class="form-control" id="productDescription" type="text" value="fdsfdsfds"/>
        </div>
        <div class="form-group">
            <label for="productPrice">Price:</label>
            <input class="form-control" id="productPrice" type="text" value="ffdhfjhdsjk"/>
        </div>
        <button type="submit" class="form-control btn btn-default">Submit</button>
    </form>
</div>
</body>
  </html>

Upvotes: 4

Related Questions