Bootstrap 4 input fields extend past padding boundaries

I have created a basic form using the following code:

<div class="container">
    <div class="jumbotron" style="width:100%">
        <h1>
            ConfigTool Web Interface
        </h1>
        <p>
            Edit the configuration variables here and click save.
        </p>
    </div>

    <div class="form-group row">
        <label class="col-2">Name:</label>
        <input class="form-control col-10" type="text" />
    </div>
</div>

Here is how it appears in the page:

https://i.sstatic.net/JuKT5.png

The issue I am facing is that the input field does not align properly with the jumbotron, as it extends beyond the padding. Here's how it looks:

https://i.sstatic.net/I1brp.png

Any suggestions on how to resolve this alignment problem?

Answer №1

Here is the solution for you

<div class="container">
    <div class="jumbotron" style="width:100%">
        <h1>
            Welcome to ConfigTool Web Interface
        </h1>
        <p>
            Manage your config variables here and save changes.
        </p>
    </div>

    <div class="form-group row">
      <div class="col-2">
        <label>Name:</label>
      </div>
      <div class="col-10">
        <input class="form-control" type="text" />
      </div>
    </div>
</div>

Remember to use col-* within a div element

Answer №2

It is recommended to apply column classes to the elements that wrap around input controls and labels when utilizing the Bootstrap grid system. The most effective structure to follow includes:

div.container > div.row > div.col-* > content
<div class="container">
    <div class="jumbotron" style="width:100%">
        <h1>
            ConfigTool Web Interface
        </h1>
        <p>
            Edit the config variables here and click save.
        </p>
    </div>
    <div class="form-group row">
        <div class="col-2">
            <label>Name:</label>

        </div>
        <div class="col-10">
            <input class="form-control" type="text" />
        </div>
    </div>
</div>

Answer №3

Your input element has Bootstrap's predefined grid classes applied to it, causing the padding from Grid classes to affect the input element directly. To resolve this, you should create separate div elements with the grid classes and place the input element inside one of these div elements.

<div class="container">
    <div class="jumbotron" style="width:100%">
        <h1>
            ConfigTool Web Interface
        </h1>
        <p>
            Edit the config variables here and click save.
        </p>
    </div>
    <div class="form-group row">
        <label class="col-2">Name:</label>
        <div class="col-10">
        <input class="form-control" type="text" />
        </div>
    </div>
</div>

For more information on creating horizontal forms with Bootstrap, please refer to the official documentation here.

Answer №4

Make sure to include the parent element for the form-group in your code. Here is an example:

 <div class="form-horizontal" >
  <div class="form-group">
    <label class="control-label col-sm-2" for="email">Email:</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="email" placeholder="Enter email">
    </div>
  </div>
</div>

Answer №5

It is important to eliminate the "row" class from the form-group as it removes padding from the div element.

<div class="form-group">
    <label class="col-2">Name:</label>
    <input class="form-control col-10" type="text" />
</div>

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

A floating transparent Turing image transformed into a clickable image

After creating an image button with a transparent black hover effect, I noticed that the image no longer functions as a "button." However, the hover effect still works. Is there a way to maintain the button functionality while keeping the color overlay? V ...

angular-ui-tab-scroll: Odd spacing between blocks and tabs, each separated individually

Greetings! I would like to express my gratitude for this wonderful library! However, I am encountering an unusual issue when trying to wrap a tabset with tabs that are included separately. This can be done either by adding individual tab elements manually ...

Ensure that the dimensions of a div remain consistent across all screen resolutions, specifically for desktops and not mobile devices

Currently I am in the process of creating a highly secure and encrypted social network, but I have hit a stumbling block. I hadn't considered how my website would display on other desktops and laptops (not mobile devices). The issue is that I set all ...

Update the min-width for col-xl @media in Bootstrap 4 by modifying the HTML styles exclusively

Is there a way to set the min-width for .col-xl to 1600px in @media using only inline HTML styling, without having to modify any Less or Sass files? I simply want to keep Bootstrap's official CDN URLs for loading the library. ...

Exploring Bootstrap: Understanding column stacking and the requirement for a new row to stack upon resizing

I am currently mastering Angular and Bootstrap for a potential job opportunity, so I have decided to create a simple demo page. However, I am facing an issue with getting a new row to stack after the last div of the previous row when resizing. Initially, m ...

Troubleshoot: Problem with iPhone Orientation on Bootstrap Framework

While working on a responsive website design, I encountered an issue that needs addressing. Initially, switching from portrait mode to landscape didn't trigger the expected responsive behavior; instead, it simply zoomed into the site. To prevent this ...

Move your cursor over one container to see the impact on another

My goal is to create a hover effect on a box that triggers another div with easing effects. Below, you'll see that the .images{} class has a 0s infinite scroll initially, but when the .box:hover > .images{} selector is activated, it changes to a 10 ...

The navigation bar seems to be missing in action

I am currently working on a project on Codepen, and I am trying to create a navbar with a dark background color and my name in a light color. However, I am facing issues as it is not displaying as expected. I followed the Bootstrap 4.0 guide available onli ...

Is Ruby on Rails featured in Designmodo's Startup Framework Kit?

I'm curious if the Startup Framework Kit from Designmodo can be seamlessly incorporated into my Ruby on Rails project. While I've had success integrating their Flat-UI-Pro using a gem, I haven't come across one for the Startup Framework yet. ...

Issues with concealing the side menu bar in Vue.js

I've been attempting to conceal the side menu bar, with the exception of the hamburger icon when in the "expanded" state. Despite my efforts to modify the CSS code, I am still struggling to hide the small side menu bar. The following images represent ...

Adjusting the content and style of a div element upon clicking, and restoring the original settings when clicked once more

There is a div with the id #increase-text-weight that displays the text "INCREASE TEXT WEIGHT". Upon clicking on it, the font weight of another div with the id #post-content should be changed to font-weight: 500 and the text inside #increase-text-weight s ...

Bootstrap dropdown malfunction

I am having trouble with my dropdown menu. The browser is cutting off the blue box in the dropdown area. I'm not sure if I need to add some CSS or make changes to the Bootstrap code to fix this issue. I haven't made any unusual modifications, jus ...

Maximizing Bootstrap: Enabling dual dropdown options side by side on a single row

I am attempting to design a login form within a Bootstrap navbar dropdown. My goal is to have the bottom item display two items side by side in the same row (login/register), but I am struggling to achieve this. You can view what it currently looks like h ...

The CSS files undergo modifications when executing the command "npm run dev"

I've been working on an open-source project where I encountered a bug. Even when there are no images to display, the "Load More" button in the web browser extension still appears. To fix this, I decided to add the class `removeButton` to the button an ...

Embed a unique custom design sheet within a Facebook iframe

I'm looking to customize the design of my Facebook feed by adding a custom style sheet inside a Facebook iframe. Here's what I have: <iframe width="1000px" height="1000px" frameborder="0" name="f1e348592ed856c" allowtransparency="true" allo ...

Styling Challenges with CSS/AngularJS Accordion in Footer

I want to create a page layout as shown below: +---------------------------+ | Auto-fill / v scrollable ^| | || | || | v| +---------------------------+ | Fixed [][][] ...

The overlay background is not covering the entire height of the container

The CSS includes a .wrapper with the style min-height: calc(50% - 30px), along with an overlay blur div to cover the entire height of the .wrapper element. Here's a link to a Codepen example showcasing this setup: https://codepen.io/palaniichukdmytro/ ...

Ways to correctly import various CSS files for individual routes in a Vuejs application

Currently, I am in the process of developing a project using Vue.js and Laravel. This project will have distinct layouts for the admin/user panel and landing page, requiring different CSS files to be loaded for each route. At the moment, I am utilizing va ...

Steps for modifying material-ui timepicker to display time in a 24-hour format

Presently, I am utilizing a Timepicker from material-ui. It is currently configured with type="time", allowing me to select times throughout the day in 12-hour increments with an AM / PM choice. However, I wish to adjust my picker to a 24-hour format, elim ...

styled-components: the parent's styles take precedence over the child's styles

image export const LogOutButton = styled.button` display: inline-block; .... `; export default styled(ThemedApp)` .... button { .... display: flex; .... } `; Upon inspection, it is evident that the Logout button (with class gBuhXv) ...