B.M
B.M

Reputation: 31

Menu with float:left and Form with Bootstrap

I got a problem with sommething very strange. I got a vertical menu which has css floating with left value and after that i got a form. The first line of the form jump to the right of the menu. But the rest of the form stay after as you can see on the picture. I don't know why i got this and i tried to fix it without success.

I use bootstrap on my page.

Here is the picture:

Picture of the page

Here is the complete code:

    <!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="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> 
        <style type="text/css">
            .menu_settings{
                width:200px;
                float:left;
                margin-left: 0px; 
                padding-left: 0px;
            }
            .li_settings{
                height:100px;
            }
        </style>
    </head>
    <body>  
        <div class="container">
            <div class="page-header">
                <h1>My Page</h1>
            </div>
            <div class=" menu_settings">
                <ul class="nav nav-pills nav-stacked">
                    <li class="active "><a href="#" class="li_settings">Home</a></li>
                    <li class="" ><a href="#" class="li_settings">Item 1</a></li>
                    <li class=""><a href="#" class="li_settings">Item 2</a></li>
                    <li class=""><a href="#" class="li_settings">Item 3</a></li>
                </ul>
            </div>

            <div class="content_settings">
                <form class="form-horizontal voffset4 fii" role="form">
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">First Name</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="firstname" placeholder="Enter First Name">
                        </div>
                    </div> 
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">Last Name</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="lastname" placeholder="Enter Last Name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2 " for="email">Email</label>
                        <div class="col-sm-4 ">
                            <input type="email" class="form-control" id="email" placeholder="Enter email">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2" for="pwd">Password</label>
                        <div class="col-sm-4"> 
                            <input type="password" class="form-control" id="pwd" placeholder="Enter password"> 
                        </div>
                    </div>
                    <div class="form-group"> 
                        <div class=" col-sm-offset-2 col-sm-2 ">
                            <button type="submit" class="btn btn-default">Valider</button>
                        </div>
                    </div>
                </form>
            </div> 
        </div>
        <div id="footer" class="voffset9">
            <div class="container">
                <p style="font-size: 16px;">Copyright 2015</p>
            </div>
        </div>
    </body>
</html>

Thanks in advance for any help ;)

Upvotes: 2

Views: 108

Answers (1)

m4n0
m4n0

Reputation: 32315

Problem:

Check How floating works. You will also be needed to set float: left to the sibling element to occupy the same row.

Solution:

You are using a CSS framework. So instead of using custom CSS, try to use the inbuilt code.

Wrap the menu with col-xs-3 and the form with col-xs-9

.li_settings {
  height: 100px;
}
<!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="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

</head>

<body>
  <div class="container">
    <div class="page-header">
      <h1>My Page</h1>
    </div>
    <div class="col-xs-3 menu_settings">
      <ul class="nav nav-pills nav-stacked">
        <li class="active "><a href="#" class="li_settings">Home</a>
        </li>
        <li class=""><a href="#" class="li_settings">Item 1</a>
        </li>
        <li class=""><a href="#" class="li_settings">Item 2</a>
        </li>
        <li class=""><a href="#" class="li_settings">Item 3</a>
        </li>
      </ul>
    </div>

    <div class="col-xs-9 content_settings">
      <form class="form-horizontal voffset4 fii" role="form">
        <div class="form-group">
          <label for="firstname" class="col-sm-2 control-label">First Name</label>
          <div class="col-sm-5">
            <input type="text" class="form-control" id="firstname" placeholder="Enter First Name">
          </div>
        </div>
        <div class="form-group">
          <label for="lastname" class="col-sm-2 control-label">Last Name</label>
          <div class="col-sm-5">
            <input type="text" class="form-control" id="lastname" placeholder="Enter Last Name">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2 " for="email">Email</label>
          <div class="col-sm-4 ">
            <input type="email" class="form-control" id="email" placeholder="Enter email">
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="pwd">Password</label>
          <div class="col-sm-4">
            <input type="password" class="form-control" id="pwd" placeholder="Enter password">
          </div>
        </div>
        <div class="form-group">
          <div class=" col-sm-offset-2 col-sm-2 ">
            <button type="submit" class="btn btn-default">Valider</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <div id="footer" class="voffset9">
    <div class="container">
      <p style="font-size: 16px;">Copyright 2015</p>
    </div>
  </div>
</body>

</html>

Upvotes: 1

Related Questions