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

Step-by-Step Guide: Customize the Background Color in an Angular 4 Select Dropdown Based on the Selected Option

I'm facing a challenge in setting the background color of a select element based on the color attribute of its currently selected option. I'm using Angular 4 for this task. An example of what I am attempting to accomplish is shown below: <se ...

The picture within the div is not appearing as expected

I am facing an issue with inserting an image in a div container using CSS and HTML. The image is not displaying properly. Here is the HTML code: <div id="wrapper"> <div id="quoteContainer"> <span class="start_img"></span> </di ...

Build a home page in HTML with full width design

My webpage currently allows scrolling to the right and left in HTML. I would like to change this functionality. What I envision is having my cup and book visible without the need for scrolling, with a background image centered on the page. <div cla ...

The box on my form is leaking my background color outside the 1px border, but only in Internet Explorer

While experimenting with background gradients and borders one day just for the fun of it, I made an interesting observation in Internet Explorer. The issue I encountered was that the background color was overflowing outside the radius border, but this onl ...

Discover the method for measuring the size of a dynamically generated list

I'm currently working on a chat box that displays messages as a list. One issue I'm facing is that when I click on the start chat button, the chat box opens but the length of the list always remains zero. How can I resolve this problem? $(docu ...

Tips for creating multiple popups using a single line of JavaScript code

I am new to JavaScript and I am attempting to create a popup. However, I am facing an issue in opening two divs with a single line of JavaScript code. Only one div opens while the other remains closed despite trying various solutions found on this website. ...

Problem arises when the DIV elements are not expanding horizontally together

Struggling to create a round corner box using divs. I have been working on it all day and can't figure out what I'm missing. If anyone could help me spot the issue, that would be great. I want the 'header' and 'footer' to exp ...

Using Vuejs to dynamically render raw HTML links as <router-link> elements

Hey there, I'm just getting started with VueJS and I've been doing some interesting experiments. I created a backend service using Python/Flask that provides me with a string of HTML code containing many tags. My goal is to render this HTML insid ...

Wordpress articles refuse to appear side by side

I've been at it for hours now, trying to solve this issue with no luck. I have a Wordpress loop on my homepage that displays post thumbnails vertically, but I want them to appear in sets of three images before starting a new line. Here's the cod ...

Aligning text in the middle of two divs within a header

Screenshot Is there a way to keep the h4 text centered between two divs? I want it to stay static regardless of screen resolution. Currently, the icon and form remain in place but the h4 text moves. How can I ensure that it stays in one spot? <!doctyp ...

Verifying the status of a checkbox label in Java using Selenium

I am currently working on an automation project using Selenium and I'm struggling to figure out how to check the status of a checkbox input. Has anyone else encountered this issue before? Here is a sample code snippet in JavaScript with jQuery: $("i ...

Alignment of Bootstrap input groups and buttons

I am looking to have the input group aligned on the left side and the "Add New" button aligned on the right side of the row. <div class="row"> <div class="input-group col-sm-6"> <input type="text" class="form-control" placehol ...

CSS. Absolute positioning in relation to a div element

I discovered a way to adjust the positioning of a div using jQuery. Check out this example. Is it possible to achieve the same result using CSS? UPDATE: I came across this solution. I also want the horizontal window scrollbar to appear if the fixed elem ...

What is the best way to extract additional values linked to the query within the array?

I have successfully retrieved all subcategories of a category using the code below. However, I am now facing an issue where I also want to fetch other fields associated with each subcategory, such as the price if the subcategory is a Product like Smartphon ...

Encountered a deployment issue when trying to deploy an HTML application on Heroku due

After uploading an html application on GitHub, I encountered an error while attempting to deploy it on Heroku: No default language could be detected for this app. HINT: This happens when Heroku is unable to automatically determine the buildpack to use f ...

On screens with smaller dimensions, the divs intersect with each other

I have a project where I need to style each letter in its own box, arranged next to each other or in multiple rows with spacing between them. Everything looks great until I resize the screen to a smaller size or check it on mobile - then the letters in the ...

How can one effectively style text to appear italic using CSS and HTML?

What is the proper method to italicize text? I have come across these four different approaches: <i>Italic Text</i> <em>Italic Text</em> <span class="italic">Italic Text</span> <span class="footnote">Italic Tex ...

Handling 404 errors in Nginx when using try_files directive for .html files

When presented with this SEF URL /attrazioni/madame-tussauds-londra.html, I am required to retrieve the actual URL which is /index.php?q=/attrazioni/madame-tussauds-londra.html I currently have a directive in place, however, it functions correctly only fo ...

Is it possible to include aria-controls in an anchor tag?

My primary navigation includes some elements that may have a secondary navigation. In order to optimize accessibility on my website, I am seeking the most effective way to show/hide the secondary nav. After brainstorming, here is what I have come up with: ...

Are HTML mistakes considered as WCAG violations?

In my quest to ensure that my website is WCAG compliant, I have done a lot of research. However, one question still lingers in my mind: Would a document with HTML errors still be considered WCAG 2.0 AA compliant? I recently ran Total Validator and it pro ...