Trouble aligning Bootstrap 4 form fields in a horizontal layout

I'm struggling to align the user image and biography form fields with the rest of my signup form in Bootstrap 4.

I've tried tweaking the CSS in various ways, but I can't achieve the desired visual effect:

  1. I want the biography and photo upload fields to be the same width as all other form fields and aligned horizontally.
  2. The photo field should be split into two equal-width sections (similar to first and last name fields), with the uploaded image horizontally aligned in one section and the button horizontally aligned in the second section.

Here is the code I'm currently using:

<>

Anyone have suggestions on how to resolve the alignment issue in this form?

Answer №1

First, it's important to remove any custom margins and padding that have been added. These are usually unnecessary with Bootstrap and can cause issues.

Next, wrap the content in a container and set a maximum width:

body {
  color: #fff;
  background: #63738a;
  font-family: 'Roboto', sans-serif;
}

.form-control {
  height: 40px;
  box-shadow: none;
  color: #969fa4;
}

.form-control:focus {
  border-color: #5cb85c;
}

.form-control,
.btn {
  border-radius: 3px;
}

.signup-form {
  font-size: 15px;
  max-width: 450px;
}

.signup-form h2 {
  color: #636363;
  position: relative;
  text-align: center;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css"/>

<div class="container signup-form">
  <form action="#" method="post">
    <h2>Create Account</h2>

    <div class="form-group">
      <div class="row">
        <div class="col"><input type="text" class="form-control" name="first_name" placeholder="First Name" required="required"></div>
        <div class="col"><input type="text" class="form-control" name="last_name" placeholder="Last Name" required="required"></div>
      </div>
    </div>

    <div class="form-group">
      <input type="text" class="form-control" name="screenname" placeholder="Username" required="required">
    </div>

    <div class="form-group avatar">
      <div class="row">
        <figure class="figure col col-md-2 col-sm-3">
          <img class="img-rounded img-responsive" src="https://bootdey.com/img/Content/avatar/avatar1.png" alt="">
        </figure>
        <div class="form-inline col-md-10 col-sm-9 col-xs-12">
          <input type="file" class="file-uploader pull-left">
          <button type="submit" class="btn btn-sm btn-default-alt pull-left">Update Image</button>
        </div>
      </div>
    </div>

    <div class="form-group">
      <label for="user-bio" class="control-label">Biography</label>
      <textarea name="user-bio" id="user-bio" class="form-control" cols="20" rows="3" placeholder="Brief biography"></textarea>
    </div>

    <div class="form-group">
      <input type="password" class="form-control" name="password" placeholder="Password" required="required">
    </div>
    <div class="form-group">
      <input type="password" class="form-control" name="confirm_password" placeholder="Confirm Password" required="required">
    </div>

    <div class="form-group">
      <button type="submit" class="btn btn-success btn-lg btn-block">Create Account Now</button>
    </div>
  </form>
</div>

Answer №2

modify the width and eliminate the float property

body {
  color: #fff;
  background: #63738a;
  font-family: 'Roboto', sans-serif;
}

.form-control {
  height: 40px;
  box-shadow: none;
  color: #969fa4;
}

.form-control:focus {
  border-color: #5cb85c;
}

.form-control,
.btn {
  border-radius: 3px;
}

.signup-form {
  width: 300px;      /* Modification made to the width */
  margin: 0 auto;
  padding: 30px 0;
  font-size: 15px;
}

.signup-form h2 {
  color: #636363;
  margin: 0 0 15px;
  position: relative;
  text-align: center;
}

.signup-form h2:before,
.signup-form h2:after {
  content: "";
  height: 2px;
  width: 30%;
  background: #d4d4d4;
  position: absolute;
  top: 50%;
  z-index: 2;
}

.signup-form h2:before {
  left: 0;
}

.signup-form h2:after {
  right: 0;
}

.signup-form .hint-text {
  color: #999;
  margin-bottom: 30px;
  text-align: center;
}

.signup-form form {
  color: #999;
  border-radius: 3px;
  margin-bottom: 15px;
  background: #f2f3f7;
  box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
  padding: 30px;
}

/* Remaining CSS styles unchanged for brevity */

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:400,700">
  <title>Bootstrap Simple Registration Form</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3839c83839681dd9980b3c2ddc2c5ddc3">[email protected]</a>/dist/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="signup-form">
    <form action="#" method="post">
      <h2>Create Account</h2>

      <!-- Form elements remain unaffected -->

      <div class="form-group">
        <button type="submit" class="btn btn-success btn-lg btn-block">Create Account Now</button>
      </div>
    </form>
  </div>
</body>

</html>

review the modifications and test the code snippet to observe the changes

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

list of current items on the sidebar that are currently being

Hey everyone, I could use some assistance with customizing my sidebar design. I am trying to implement an active state in my sidebar using JavaScript. I attempted to utilize the element.css() method to apply styles when an element is clicked. However, I no ...

Leverage the leftover vertical space effectively with Bootstrap 4

I'm interested in maximizing the vertical space for the 'grid' id. <div class="container fluid"> <div class="row mb-2"> <div class="col"> <h2><i class="fas fa-map-marker-alt"></i> ...

Is it possible to disregard any spaces within the content of an <option> element?

In my current project, I am facing an issue where a Django server is sending JSON data to a template with Vue.js running on it. The problem arises from the fact that some values in the JSON data have trailing spaces, causing complications. I am looking for ...

Google Maps is experiencing difficulties maintaining its longitude and latitude coordinates within the Bootstrap tabbed user interface

I implemented ACF's Google Map to display a map on my webpage. I followed the instructions closely and made some minor modifications to the map js for styling purposes. One key change I had to make was in this section to ensure the map loads correctly ...

The background size cover feature is not functioning properly on mobile devices, especially on longer pages

In my Next.js project, I am encountering an issue with the background image not displaying on longer pages when viewed on a Google Pixel 3a device. Here is how it looks on shorter pages that do not exceed the viewport height: https://i.sstatic.net/jJBTy.pn ...

How do you toggle the visibility of a dependent <select> in an HTML form?

In my HTML jQuery form, I need to display a second select box based on the user's selection in the first select box. Should I use .show() to reveal a previously hidden div or should I use .append() to populate an empty select element? In other words, ...

I am having issues with my JavaScript code, I could really use some assistance

Currently, I am developing a custom file search program. The goal is to have a textarea where users can input text, which will then generate a clickable link below it. However, I am facing issues with the current implementation. Below is the snippet of my ...

Having difficulty converting the string data to HTML using JavaScript in a Node.js Express application

In my app.js file, I will be sending data to an EJS file. app.get('/', function (req, res){ Blog.find({}, function(err, fountItems){ Blog.insertMany(defaultBlog, function(err){ }) } res.render( ...

Tips for implementing events with AngularJS Bootstrap Colorpicker

I am having trouble understanding how events function with Angular Bootstrap Colorpicker. I have forked a Plunker from the developer's example. Unfortunately, there are no examples provided for using events. It would be great if events like colorpick ...

Python script unable to locate div popup using Selenium

Recently, I've been working on enhancing my selenium skills, but I'm facing a challenge in finding a solution to this particular issue. While experimenting with the functionality of the page located at: www.omegle.com When using selenium to cli ...

Setting an ElementImpl property explicitly in EMF/GMF/Papyrus outside of the code

I am working with an EMF-model and its generated editor. In this model/editor, there is a connection between Element "Unit"(U) and "Specification"(S). My goal is to have a specific CSS style for S if at least one U satisfies S. Unfortunately, I have not fo ...

Error: Invalid Argument - The argument 'PanelController' is expected to be a function, but it is undefined

Here is a snippet of my HTML code: <body ng-controller="StoreController as store"> ........... <section ng-controller="PanelController as panel"> <ul class="nav nav-pills""> <li ng-class="{active:panel.isSe ...

What is the best way to include dynamic arguments using template literals?

Looking for assistance with a piece of code function createAnswerElement(answer, index) { const key = `${answer}-${index}`; return ` <p class="delete" onclick=someSillyFunc(${key})>x</p> `; } function someSillyFunc(key) { cons ...

Is it possible for the .find() method to extract values from <a> tags?

I'm currently working on retrieving values from an anchor tag using jQuery instead of a button in my HTML. I want to style it with images because a button doesn't match the look of my website. Here's what I've been trying: var mssg_i ...

Add a class by utilizing the :class attribute

I reviewed the documentation, but I am still struggling to implement this in my project. Initially, I simply want to display a specific class using vue.js that I can later modify dynamically. I just need to establish the default behavior of that class, so ...

I'm having trouble locating the corresponding end tag for "<%". How can I resolve this issue?

Here lies the issue: <% for(let i = 0; i < <%= elements %>.length; i++){ %> <li><%= elements[i] %></li> <%}%> ...

Prevent iOS from scrolling both horizontally and vertically

I'm currently in the process of developing a web app and I want to prevent horizontal overflow (elastic band) type scrolling. Despite trying various solutions, such as: html, body {width: 100%; overflow-x: hidden;} Nothing seems to be effective... ...

Make sure to enable contentEditable so that a <br> tag is inserted

When using a contentEditable, it automatically wraps words to create a new line once the width of the editable area is reached. While this feature is useful, I am facing an issue when parsing the content afterwards as I need it to insert a <br> tag ...

Modifying CSS using jQuery in a PHP While Loop

I've been racking my brain trying to solve this issue, experimenting with different approaches but so far, no luck. Question: How can I dynamically change the color of a specific div within a PHP while loop using jQuery after receiving an AJAX respon ...

What are some techniques for creating an HTML element that remains fixed on the page after scrolling past a certain height, even though it is originally part of

I am trying to achieve a specific effect with a <section></section> element on my web page. Once the user scrolls past the section, I want it to remain fixed at the top of the screen even as they continue scrolling downwards. This is in an Ang ...