Having difficulties in expanding my input bar to 100% width and center aligning it

Creating a webpage in a jsp file with the help of spring boot, I've utilized bootstrap for the design. I'm facing some challenges as I'm unable to widen my input box to width:100% on both the login and new registration pages. Additionally, centering the input field is proving to be tricky for me.

Below, I've included my CSS and HTML code.

Here is my CSS code snippet:

<style media="screen">
    body{
   margin: 0;
   padding:auto;
   text-align: center;
   font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   background-image:linear-gradient(120deg,#b134eb,#5efff7);
   min-height : 160vh;
   } 
   .form-control{
  display: block;
  margin-right: auto;
  margin-left: auto;
   }
   </style> 

Shown below is the HTML form code:

<body>[login page output[\]\[1\]][1]
      
       <c:choose>
      <c:when test="${mode=='MODE_REGISTER' }">
            <div class="container text-center">
                <h3>New Registration</h3>
                <hr>
                <form class="form-horizontal" method="POST" action="save-user">
                ...
                ...
                ...
                ...
                ...
                ...
            </div>
            
            
            
        </c:when> 
        
        
        <c:when test="${mode=='MODE_LOGIN' }">
            <div class="container text-center">
                <h3>User Login</h3>
                <hr>
                <form class="form-horizontal" method="POST" action="/login-user">
                ...
                ...
                ...
                ...
                ...
            </div>
        </c:when>
    </c:choose>
</body>

Check out the output of the registration form here

I appreciate any assistance in aligning the input field to the center. Thank you!

Answer №1

To expand the input box, switch to div or even better, use .form-group div { margin:auto; } to center them if they are small in size.

To center the radio buttons, apply display: flex as well.

Below is a working snippet:

.form-group div {
  margin: auto;
  display: flex;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>


<form class="form-horizontal" method="POST" action="save-user">
  <input type="hidden" name="id" value="${user.id }" />
  <div class="form-group">
    <label class="control-label col-md-3">Username</label>
    <div class="col-md-7">
      <input type="text" class="form-control" name="username" value="${user.username }" />
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-md-3">First Name</label>
    <div class="col-md-7">
      <input type="text" class="form-control" name="firstname" value="${user.firstname }" />
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-md-3">Last Name</label>
    <div class="col-md-7">
      <input type="text" class="form-control" name="lastname" value="${user.lastname }" />
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-md-3">Age </label>
    <div class="col-md-3">
      <input type="text" class="form-control" name="age" value="${user.age }" />
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-md-12">Gender </label>
    <div class="col-12">
      <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" name="gender" id="male" value="Male">
        <label class="form-check-label" for="Male">Male</label>
      </div>
      <div class="form-check form-check-inline">
        <input class="form-check-input" type="radio" name="gender" id="Female" value="Female">
        <label class="form-check-label" for="Female">Female</label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-md-3">Password</label>
    <div class="col-md-7">
      <input type="password" class="form-control" name="password" value="${user.password }" />
    </div>
  </div>
  <div class="form-group ">
    <input type="submit" class="btn btn-primary" value="Register" />
  </div>
</form>
</div>

</c:when>

Answer №2

To achieve full width, apply max-width: 100%, and for centering, utilize the following CSS code:

.form-group div{
display: flex;
justify-content: center;
align-items: center;
}

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

Issues with Bootstrap Contact Form submission

I found a helpful tutorial for creating a form at the following link: After following the tutorial, I added these scripts to the bottom of my contact form HTML: <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script> ...

Utilize CSS to position an element absolutely above the scrollbar

I'm encountering an issue with CSS absolute positioning, where the element appears above the scrollbar... Here is my code: document.addEventListener("DOMContentLoaded", () => { const h1 = overflow.querySelector("header h1") overflow.ons ...

Centering bootstrap columns in a WordPress template

I am facing an issue with aligning columns in a bootstrap section within a Wordpress template that I am working on. The problem is that the columns on the second line of the row are not centered. Currently, the layout displays 4 columns in the top row and ...

How to show specific images by clicking on particular items in Ionic 3 on a separate page

Can someone assist me with displaying specific images from a slider gallery? I am struggling to figure out how to show only the January edition when clicking on it in eighteen.html, while hiding the February and March editions. It has been 2 days of unsucc ...

Navigate to the line situated at the exact midpoint vertically

I have a div with child elements, each containing a line of text. <div id="aboutxt"> <div class="line">TEXT_LINE_ONE</div> <div class="line">TEXT_LINE_TWO</div> <div class="line">TEXT_LINE_THREE</div> ...

Convert the MySQL DATE column from numerical month to full month name

I'm having trouble figuring out a simple solution. I'm using the code below to generate a tree grid from a MySQL database. $sql2 = mysql_query("SELECT DISTINCT YEAR(date) FROM blogs ORDER by YEAR(date) desc")or die(mysql_error()); $archive .= "& ...

Problems with Owl Carousel presentation

I have integrated owl carousel to animate the data from my WordPress Advance Custom Fields. However, I am facing an issue where the items are appearing below each other instead of in a carousel format as intended. I referenced the following resources for ...

What is the best way to apply hover effects to all links except the one being hovered over, using a combination of javascript, jquery,

While browsing the web, I came across a fascinating hover effect that I'm eager to replicate in a website's navigation bar. This effect doesn't just change the link you hover over, but it alters every other link in a unique way. When hoverin ...

Deactivate event handling for viewport widths below a specified threshold

Currently, I am attempting to deactivate a script when the width of the window falls below 700px. Despite reviewing suggestions from various sources, I have not been successful so far. window.onresize = function () { if(window.innerWidth < 700) { ...

Is it possible to serve CSS using relative paths that go beyond the URL root?

I've encountered a file path issue with my HTML and CSS files. My HTML file is located in: src/test/html/index.html And the corresponding CSS file is in: src/test/css/index.css In the HTML file, the CSS is linked using: <link rel="stylesheet" ...

The data-src tags are functioning properly in the index.html file, but they are not working correctly in angular

I'm still learning about Angular and JavaScript, so please bear with me if my questions seem silly. I've been trying to add a theme to my Angular project. When I include the entire code in index.html, everything works fine. However, when I move ...

Using JQuery to locate radio buttons that have been selected based on a variable

In my JavaScript code, I have created a variable called "thisRadio" to represent a dynamically generated div containing multiple radio buttons. Currently, one of these radio buttons may be checked and my goal is to find the checked radio button within this ...

The button click event fails to trigger after entering text into an input field

I created a basic calculator. Users can input a value in the designated field and then click on the '+' button. The cursor stays in the input field, allowing users to immediately enter a new value after clicking the '+'. The mouse poi ...

Complete a form when a link or button on the webpage is clicked

I have a variety of links and buttons on my webpage, and they are generated dynamically. I am unable to assign an onclick event to each one individually. My goal is to submit form data to the next page whenever any link or button on the page is clicked. ...

Verifying that dynamically generated textboxes contain values

I am facing an issue with my code where I am generating dynamic IDs like checc1, checc2 for dynamically created textboxes. How can I assign these values to a variable called 'boxc' one by one? function GetDynamicTextBox(value) { var nextRowID ...

Detect if the user is using Internet Explorer and redirect them to a different

My web application is having trouble rendering in Internet Explorer. In the meantime, I would like to detect if the user is using IE and redirect them to a different page specifically for IE visitors. What is the best way to accomplish this? Should I use ...

Eclipse Content Assist feature appears to be malfunctioning as it fails to display

Having an issue with Eclipse on Win 10 (64bit) when working with JavaScript projects. I've tested this problem on both Eclipse Photon and version 2018-09 (64 bit versions) and encountered the same problem on both instances: After creating a new JavaS ...

Keep HTML in sync across browser and server

Is there a way to efficiently update a large unordered list in a web application without sending the entire list over the network or resorting to pagination, while ensuring it stays synchronized with a memoized server-generated copy? ...

Create a basic chart using JavaScript

I am looking to replicate a specific chart using JavaScript. The red point in the chart is variable. So far, I have attempted to create it using the flot library: var d3 = [[7,7]]; $.plot("#placeholder", [{ data: d3, points: { show: true } }], { ...

The ASP.NET Core framework features a static top menu bar and a fixed left-hand side menu for seamless navigation

I am currently utilizing ASP.NET Core 6, jQuery, and Bootstrap in my project. I have a specific screen layout where I want the left-hand side menu and the top menu to remain fixed in their positions, while only the input details section should be able to s ...