Mike Beers
Mike Beers

Reputation: 73

Why does nested Row/Column extend past container

Still learning web dev so here is my question. I am wondering why when using a container class at the very beginning of my layout, and when adding a row with two Col-md-6 columns, the content extends past the container. The two columns with the forms inside extend past the jumbotron on both sides. Just confused. I think if I add an another container it would even it all out. Just dont know why that would be needed.

var toggle = function(){
	var exists = document.querySelector("#existButton");
	console.log(exists.innerHTML);


	if(exists.classList.contains("btn-warning")){
		exists.classList.remove("btn-warning");
		exists.classList.add("btn-info");
		exists.innerHTML = "copy";
		//document.getElementById("#existButton").innerHTML = 'check'
	} else {
		exists.classList.remove("btn-info");
		exists.classList.add("btn-warning");
		exists.innerHTML="check";
		//document.getElementById("#existButton").innerHTML = 'copy'
	}

	
	

}
body{
	/*background: repeating-linear-gradient(
		to right,
		#050210,
		#050210 50px,
		#271f41 50px,
		#271f41 100px
	)*/

	background-image: url(images/body_background.png); 
	
}
.jumbotron {
	margin-bottom: 0;
	background-color: #cbd0d3;

}

.container .jumbotron{
	border-radius: 0px;
}
.navbar{
	margin-bottom: 0;
	background-color: #44abe2;
	margin-top: 30px;

}

.navbar-default .navbar-nav>li>a {
	color: white;

}

.navbar .navbar-default {
	border-radius: 0px;
}

.navbar-default .navbar-brand{
	color: white;
}

.automatic {
	background-color: #6e8a99;
	padding-bottom: 40px;
	border-bottom-left-radius: 6px;
	
}

.manual {
	background-color: #83929a;
	padding-bottom: 40px;
	border-bottom-right-radius: 6px;
}

#ml-2{
  padding-right:0;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="style.css">


    <title>Mailbox Creator</title>
  </head>
  <body>
    <div class="container">
      <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="#">Brand</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNavDropdown">
          <ul class="navbar-nav">
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Mailbox Management
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                <a class="dropdown-item" href="#">User Mailbox Management</a>
                <a class="dropdown-item" href="#">Resource Mailbox Management</a>
                <a class="dropdown-item" href="#">Mailbox Update Management</a>
              </div>
            </li>
          </ul>
          <ul class="navbar-nav ml-auto">
            <li class="nav-item">
              <a class="nav-link">Hello Username</a>
            </li>
          </ul>
        </div>
      </nav>


      <div class="jumbotron">
        <h1 class="text-center">Mailbox Creator Pro</h1>
      </div>



      <div class="row ">
        <!--  ***************************************** -->
        <!--  **********  Automatic Form  ************* -->
        <!--  ***************************************** -->
        <div class="col-md-6 automatic">
          <form>        
            <h4 class="text-center pb-2"><u>Automatic</u></h4>
            <div class="form-group row">
              <label class="col-md-3 col-form-label" id="ml-2" for="accountName">Account Name</label>
                <div class="col-md-6">
                  <input class="form-control form-control-sm " type="text" name="accountNameAuto" value="" placeholder="Account number">
                </div>  
                <div class="col-md-2">
                  <button type="submit" class="btn btn-success btn-sm ">Create</button>
                </div>
            </div>    
          </form>
          <form>
            <div class="form-group row">
              <label class="col-md-3 col-form-label"  id="ml-2" for="emailCheckAutomatic">Does account have email?</label>
              <div class="col-md-6 mt-3">
                <input class="form-control form-control-sm" type="text" name="emailCheckAutomatic" value="" placeholder="check for email account">
              </div>
              <div class="col-md-2">
                <button type="submit" class="btn btn-info btn-sm mt-3">Check</button>
              </div>
            </div>
          </form>
          <textarea class="form-control form-control-sm mb-1" ></textarea>
        </div>


        <!--  ***************************************** -->
        <!--  **********  Manual Form  **************** -->
        <!--  ***************************************** -->
        <div class="col-md-6 manual">
          <form>        
            <h4 class="text-center pb-2"><u>Manual</u></h4>
            <div class="form-group row">
              <label class="col-md-1 col-form-label " for="accountName">Email</label>
              <div class="col-md-5">
                <input class="form-control form-control-sm " type="text" name="accountNameManual" value="" placeholder="Email">
              </div>
              <label class="col-md-2 col-form-label" for="accountName">Account</label>
              <div class="col-md-2">
                <input class="form-control form-control-sm" type="text" name="" value="" placeholder="S#">
              </div>
              <div class="col-md-1">
                <button type="submit" class="btn btn-success btn-sm">Create</button>
              </div>
            </div>        
          </form>      
          <form>
            <div class="form-group row">
              <label class="col-md-1 col-form-label ml-1" for="emailCheckAutomatic">Email exist?</label>
              <div class="col-md-5 mt-3">
                <input class="form-control form-control-sm" type="text" name="emailCheckAutomatic" value="" placeholder="check for email account">
              </div>
              <div class="col-md-4 mt-3">
                <a href="#" class="btn btn-info btn-sm" id="existButton" onclick="toggle()">Check</a>
              </div>
              <div class="col-md-1 mt-3">
                <button type="submit" class="btn btn-warning btn-sm"  >Copy</button>
              </div>
            </div>
          </form>
          <textarea class="form-control form-control-sm mb-1" ></textarea>
        </div>

      </div><!-- End Row -->


    </div> <!--  End Container  -->



    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    <script src="scripts/script.js"></script>
  </body>
</html>

Upvotes: 2

Views: 356

Answers (2)

Carol Skelly
Carol Skelly

Reputation: 362350

In Bootstrap, left/right padding (15px) on the columns is used to create the gutter/spacing between columns (col-*). The .row counteracts the padding by using negative margins (-15px) so that the outer columns (first/last) in any row are aligned to the edge of the container (and other content on the page).

enter image description here

In your case, a background-color has been applied to .automatic and .manual which are columns. Because the bg color is on the columns (and not the content of the columns), it appears that the columns are overflowing the row (which they actually are as explained above for the gutter.)

So for side alignment with other items in the container, you should apply the background-color to the content of the columns instead...

Demo: https://www.codeply.com/go/s07FmLZKuY

.automatic {
    padding-bottom: 40px;
    border-bottom-left-radius: 6px;
}

.automatic > form {
    background-color: #6e8a99;
}

.manual {
    padding-bottom: 40px;
    border-bottom-right-radius: 6px;
}

.manual > form {
    background-color: #6e8a99;
}

You may also want to add padding to the inner forms if you don't want their content against the edge.


More on the "gutter" in the Bootstrap docs..

Each column has horizontal padding (called a gutter) for controlling the space between them. This padding is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.

Upvotes: 1

WebDevBooster
WebDevBooster

Reputation: 14954

Why does nested Row/Column extend past container

That's because a Bootstrap row normally has gutters i.e. 15px margin on each side of each Bootstrap column that sits inside a Bootstrap row. So, that results in 15px margins on the outside and 30 px between the columns.

To remove the gutters, add the class no-gutters to the row.

To add some padding to the columns now, you can add a spacing class like px-3 to the columns. px-3 means "horizontal padding 3 units".

Upvotes: 1

Related Questions