Issue with Bootstrap 3: Element refuses to remain within the defined width of the div container

While utilizing bootstrap 3 within a small div, I noticed that when I enlarge the window by dragging it horizontally, the fields (username and password input fields) that should remain inside the div end up shifting towards the center of the window. Can anyone help explain why this is happening? Here are the CSS and HTML snippets:

<body>
  <div class="login">
    <div class="container">
        <div class="col-md-12">
          <div class="row">
          <form action="https://www.blah/login"/>
          <h3>Login</h3>
            <div class="col-xs-4">UserName:</div>
              <div class="col-xs-8"><input class="rounded white" type="text" name="username" placeholder="Username:" required/><br></div>
            <div class="col-xs-4">Password:</div>
              <div class="col-xs-8"><input class="rounded white" type="password" name="password"  placeholder="Password:" required/><br></div>
          <input type="checkbox" name="retrieve" value="true"/>I forgot my password.
          <ul class="no-bullets">
            <li><input class="color-brown white rounded float-left" type="submit" name="register" value="Submit Now"></li>
            <li><input class="rounded margin-left-5px" data-dismiss="modal" type="submit" value="Cancel"></li>
          </ul>
          </div>
        </div>
    </div>
  </div>
</body>

CSS----

.login {
  height: 200px;
  width: 330px;
  max-width: 330px;
  padding: 10px 20px 10px 20px;
  background-color: #242424;
  border: 1px solid #545454;
  border-radius: 5px;
  color: #ddd;
}

JS Fiddle

Answer №1

The labels in the elements (.col-xs-4) are set to have a width: 33.33333%.

The input fields in the elements (.col-xs-8) are set to have a width: 66.6666667%.

On narrow screens, the labels and inputs appear close together due to these small width values.

As the screen expands, the gap between label and input increases as the width values expand.

To address this issue, apply a width constraint to the container.

Simply add this CSS style to the container class:

.col-md-12 { max-width: 250px; }

I have tested this solution in Chrome and it is effective. For a live demonstration, check out this link: http://jsfiddle.net/y0psw5dn/

Answer №3

Give this a try.

<div class="login">
    <div class="row">
    <div class="col-md-12">
        <form action="https://www.blah/login" />
         <h3>Login</h3>

        <div class="col-xs-4">Username:</div>
        <div class="col-xs-8">
            <input class="rounded white" type="text" name="username" placeholder="Enter your Username" required/>
            <br>
        </div>
        <div class="col-xs-4">Password:</div>
        <div class="col-xs-8">
            <input class="rounded white" type="password" name="password" placeholder="Enter your Password" required/>
            <br>
        </div>
        <input type="checkbox" name="retrieve" value="true" />Forgot your password?
        <ul class="no-bullets">
            <li>
                <input class="color-brown white rounded float-left" type="submit" name="register" value="Sign In Now">
            </li>
            <li>
                <input class="rounded margin-left-5px" data-dismiss="modal" type="submit" value="Cancel">
            </li>
        </ul>
                </div>
    </div>
</div>

.login {
    height: 200px;
    width: 330px;
    max-width: 330px;
    padding: 10px 20px 10px 20px;
    background-color: #242424;
    border: 1px solid #545454;
    border-radius: 5px;
    color: #ddd;
}

Check out this JSfiddle link for more information.

Answer №4

Simply place the .login division below the .container division. Here is the code snippet:

<div class="container">
    <div class="login">

Take a look at the example in this demo.

I made some adjustments to your layout. You can view the updated version in this updated demo

Answer №5

Utilizing Bootstrap 3 in this example, take a look at the code below. It seems like your HTML structure is not properly organized. Understanding the row and columns layout is crucial for its intended purpose.

There are multiple instances where you open a div tag without closing it at the appropriate location.

The following HTML Code was used:

<div class="container">    
    <div class="col-md-12 login">         
      <form action="https://www.blah/login"/>
      <h3>Login</h3>
       <div class="row">
            <div class="col-xs-4">UserName:</div>
            <div class="col-xs-8">
                <input class="rounded white" type="text" name="username" placeholder="Username" required/><br>
            </div>
        </div>
         <div class="row">
            <div class="col-xs-4">Password:</div>
            <div class="col-xs-8">
                <input class="rounded white" type="password" name="password"  placeholder="Password" required/><br>
            </div>
        </div>
         <div class="row">
             <div class="col-md-12">
                <input type="checkbox" name="retrieve" value="true"/> I forgot my password.
             </div>
         </div>
         <div class="row">
             <div class="col-md-6">
               <input class="bg-default btn-font" type="submit" name="register" value="Submit Now">
              </div>
             <div class="col-md-6">
               <input class="bg-default btn-font" data-dismiss="modal" type="submit" value="Cancel">
              </div>
         </div>
      </div>       

CSS code snippet:

.login {  height: 200px; width: 330px;  max-width: 330px;  padding: 10px 0px 10px 20px;  background-color: #242424;  border: 1px solid #545454;  border-radius: 10px;  color: #ddd; }  .btn-font{   color: #000; }

Check out the live demo here:

Click Here to View Demo

Answer №6

Greetings! Kindly review the code snippet below to ensure it is contained within a designated container.

<div class="container">
  <div class="login">
    <div class="col-md-12">
            <div class="row">
      <form action="https://www.blah/login"/>
      <h3>Login</h3>
        <div class="col-xs-4">UserName:</div>
          <div class="col-xs-8"><input class="rounded white" type="text" name="username" placeholder="Username:" required/><br></div>
        <div class="col-xs-4">Password:</div>
          <div class="col-xs-8"><input class="rounded white" type="password" name="password"  placeholder="Password:" required/><br></div>
      <input type="checkbox" name="retrieve" value="true"/>I forgot my password.
      <ul class="no-bullets">
        <li><input class="color-brown white rounded float-left" type="submit" name="register" value="Submit Now"></li>
        <li><input class="rounded margin-left-5px" data-dismiss="modal" type="submit" value="Cancel"></li>
      </ul>
      </div>
    </div>
</div>

Feel free to access the demonstration here

Answer №7

Why not update the initial structure of your HTML like so:

 <div class="container">
         <div class="row-fluid">
             <div class="login">   

The issue lies within your HTML structure, as there are several errors present. You can enhance it by familiarizing yourself with the Bootstrap grid system.

This error is a result of an incorrect sequence in the structure.

Take a look at this demo on jsfiddle to see it in action:

Check out the DEMO


I've made some modifications to your code, you might find them helpful:

.login {
  height:280px;
    max-width:250px;
  padding: 10px 20px 10px 20px;
  background-color: #242424;
  border: 1px solid #545454;
  border-radius: 5px;
  color: #ddd;
}
.temp_div{
    float: left;
    margin-top: 10px;
}
.forgetPass_check{
    padding-right:5px;
    vertical-align:bottom;
    padding-left: 15px;
}
.forgetPass_label{
    padding-left:10px;
}
.no-bullets{
    list-style-type: none;
    margin: 0;
    padding-left: 15px;
}
ul.no-bullets li{
    float: left;
    padding-right: 20px;
    color:black;
}
 <div class="container">
         <div class="row-fluid">
             <div class="login">                 
                  <form action="https://www.blah/login"/>
                  <h3 class="text-center">Login</h3>                 
                 <div class="col-xs-8"><label>UserName:</label><input class="rounded white" type="text" name="username" placeholder="Username:" required/></div>
                 <div class="col-xs-8"><label>Password:</label><input class="rounded white" type="password" name="password"  placeholder="Password:" required/></div>
                 <div class="temp_div"> 
                      <div class="forgetPass_check">
                          <input type="checkbox" name="retrieve" value="true"/><label class="forgetPass_label">I forgot my password.</label>
                      </div>
                      <div class="button_wrapper">
                          <ul class="no-bullets">
                            <li><input class="color-brown white rounded float-left" type="submit" name="register" value="Submit Now"></li>
                            <li><input class="rounded margin-left-5px" data-dismiss="modal" type="submit" value="Cancel"></li>
                          </ul>
                      </div>
                  </div>                 
             </div>
        </div>
  </div>

Check out the modified code in action here:

Please Check Out the Modified Version

You can also view this alternative version:

Another Attempt

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is the Slick Slider displaying previous and next buttons instead of icons?

I'm currently working on creating a slider using the slick slider. Everything seems to be functioning properly, but instead of displaying arrows on the sides, it's showing Previous and Next buttons stacked vertically on the left side. It appears ...

Acquire feedback from PHP using SweetAlert notifications

I need to update my HTML form to function like this: <script> function getName() { var name = $('#name').val(); var url_send = 'send.php'; $.ajax({ url: url_send, data: 'name=' + name, ...

Tips for showing just one table data cell (<td>) with identical class:

I'm facing a challenge with jQuery, HTML, and CSS. I'm currently in the process of designing a website for a railway company. The Home page is completed, but I've hit a roadblock on the tickets page. Using just HTML, CSS, and jQuery to build ...

Retrieve input value from a jQuery template

I've created a template <div id="template" style="display: none;"> <strong>Name</strong>: <span class="name"></span><br/> <input type="number" id="amount"> <button type="button" onclick="App.submit ...

Creating a CSS layout with three columns where the first column's width is unspecified and the second

I am looking to create a three column layout with specific width requirements. The first column should adjust based on content, the second column should fill the space between the first and third columns, and the third column should have a fixed width. Add ...

Javascript eval function providing inaccurate results

I have encountered a problem while using eval() for a calculator I am developing. When I input the following code: console.log(eval("5.2-5")); The output is: 0.20000000000000018 I am confused as to why this is happening. Thank you for your assistance. ...

Automatically adjust sizes with div elements

How can I automatically resize this iframe within a div? My current method is not effective. <iframe src="http://www.gamepuma.com/external.html?http://data.gamepuma.com/games/06/crash-bandicoot.swf" width="600" height="400" frameborder="0" margin ...

What is the best way to create an overscroll bounce effect for a list with a fixed height, even when the list items have not surpassed the height of the container?

When using a fixed-height ul with overflow scroll, the list will not have an overscroll bounce effect until its items exceed the height of the list. However, on mobile, I want the list container to have an overscroll bounce effect even when its items hav ...

By employing the pseudo selector ::after, one can enhance the design

Trying to align 2 images next to each other, I am floating one left and the other right with the intention of clearing the float using the ::after pseudo selector. The surrounding text is expected to flow in between the images. I often struggle with maki ...

MUI: Interaction with a button inside a MenuItem when not interacted with MenuItem itself?

Currently, I am utilizing MUI's Menu / MenuItem to create a menu of missions / tasks similar to the screenshot below: The MenuItem is interactive: // ... other code <MenuItem value={mission.issueIdentifierId} sx={{px: ...

Jssor's dynamic slider brings a touch of sophistication to preview upcoming images

Incorporating the jssor nearby slider to create a nearly fullscreen display. The goal is to set the opacity of upcoming images to 0.25 when they are not in the main viewport, giving the edges of the upcoming and previous slides a slight transparency. < ...

Conceal the div if it remains unhidden within the following 10 seconds

This piece of code is designed to show a loader image until the page finishes loading. Here is the code snippet: document.onreadystatechange = function () { var state = document.readyState if (state == 'interactive') { $('#unti ...

"Discover the step-by-step process for displaying the menu on a WordPress

After installing the new classifieds theme on my Wordpress website, I noticed that the menu from the previous theme is still showing up. However, when I hover over the menu, it disappears and only reappears once my cursor is no longer hovering over it. ...

Create a draggable and droppable file upload container that functions similarly to an input with the type "file"

My goal is to create a native HTML5 multiple file upload feature using drag and drop functionality. Despite following tutorials like and http://www.html5rocks.com/en/tutorials/file/dndfiles/, I have not yet found the exact solution I am looking for. Ess ...

Tips for containing a range slider within a div element in a flexbox container

I am currently using Javascript to generate a grid of images, and I want to include a range slider at the bottom of one of the images. Here is a simplified version of my code using flex-container: <style> .flex-container { display: flex; fle ...

Padding will not completely fill the <li> and <div> elements

Looking to create a sleek menu bar that's 40px tall and fills up 80% of the browser width. The challenge arises when trying to center the text within the menu items. Despite adjusting padding for alignment, there's still a small gap because of & ...

Switching the file format from HTML to .ASP resulted in the loss of the website's design elements and images

After initially creating an HTML file, I decided to rename it with a .asp extension for uploading online. To do this, I copied the original HTML file and moved it into a folder containing .asp files. However, after replacing the existing file, my website l ...

Issue with alignment at bottom of page

It seems like my footer is not aligning properly with the full page. The body of the site is contained within a class, so the bottom of the footer lines up with the body. However, since it takes up 100% of the screen, it pushes the site to the right by th ...

Controlling the Alignment of HTML Div Elements

I'm struggling to align some of these divs, especially centering them. I want the page to closely resemble this image: Here are the specific requirements: 1) The header text should be centered vertically and placed in a separate div with a black back ...

Only apply the CSS filter alpha to the parent element and not its children

I am working on implementing an alert message box using HTML and CSS. Below is the code I have so far: <div class="dim" id="msg"> <div class="dialog_wrapper"> <div class="dialog" id="msg_value"></div> ...