Having difficulty aligning the button in the center

I encountered an issue trying to center a button, I attempted to use text-align: center, but it didn't have the desired effect.

.regis-btn {
  border-radius: 0px;
  text-align: center;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  -o-border-radius: 10px;
  -ms-border-radius: 10px;
}
<form action="" method="post" role="form>
  <div class="form-group>
    <label for="cellphone>Cellphone Number</label>
    <input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone>
  </div>
  <div class="form-group>
    <label for="name>Username</label>
    <input type="text" class="form-control" id="name" placeholder="Username>
  </div>
  <div class="form-group>
    <label for="seriesnum>Series Number</label>
    <input type="text" class="form-control" id="seriesnum" placeholder="Series Number>
  </div>
  <button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;>
           <span> Register </span>
       </button>
</form>

Answer №1

Feel free to give this a shot:

<div class="form-group text-center"> 
    <button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;"></button>
</div>

Answer №2

text-align: center simply centers the content inside the element. In this case, you centered the text inside the button.

If the button is the only element in the row, consider wrapping it in a div instead.

Check out this demo to see how it works:

.btn-container {
    text-align: center;  
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form action="" method="post" role="form">
   <div class="form-group">
       <label for="cellphone">Cellphone Number</label>
       <input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
   </div>
   <div class="form-group">
       <label for="name">Username</label>
       <input type="text" class="form-control" id="name" placeholder="Username">
   </div>
   <div class="form-group">
       <label for="seriesnum">Series Number</label>
       <input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
   </div>
   <div class="btn-container">
       <button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
           <span>Register</span>
       </button>
   </div>
</form>

Answer №3

Ensure the button is centered using margin: 0 auto; and display: block;.

.regis-btn {
  border-radius: 0px;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  -o-border-radius: 10px;
  -ms-border-radius: 10px;
  text-align: center;
  margin: 0 auto;
  display: block;
}
<form action="" method="post" role="form>
  <div class="form-group">
    <label for="cellphone">Cellphone Number</label>
    <input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
  </div>
  <div class="form-group">
    <label for="name">Username</label>
    <input type="text" class="form-control" id="name" placeholder="Username">
  </div>
  <div class="form-group">
    <label for="seriesnum">Series Number</label>
    <input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
  </div>
  <button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
                  <span>
                     Register
                  </span>
              </button>
</form>

Answer №4

Solution: Feel free to utilize the code snippet below.

.regis-btn {
    border-radius: 0px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -o-border-radius: 10px;
    -ms-border-radius: 10px;     
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form action="" method="post" role="form">
   <div class="form-group">
       <label for="cellphone">Cellphone Number</label>
       <input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
   </div>
   <div class="form-group">
       <label for="name">Username</label>
       <input type="text" class="form-control" id="name" placeholder="Username">
   </div>
   <div class="form-group">
       <label for="seriesnum">Series Number</label>
       <input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
   </div>
   <div class="text-center">
   <button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
       <span> Register </span>
   </button>
   </div>
</form>

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

Achieving Vertical Tabs on Larger Screens and Horizontal Tabs on Smaller Screens with Css Bootstrap 4

I'm attempting to create tabs that are vertical on wider screens and horizontal on smaller screens, but I'm unsure of how to accomplish this. I have experimented with adding flex-md-column and flex-lg-column to the nav tabs: <ul class="nav na ...

Postpone the execution of the toggleClass function

I have a tab that, when clicked, fades in to reveal content loaded with AJAX. However, the content loads immediately upon clicking the button. I attempted to use toggleClass with delay, but it was unsuccessful. How can I effectively delay the loading of t ...

What is the best way to utilize mouseenter and mouseleave events concurrently?

I need some assistance with my website's star rating feature. When a user hovers over the stars, a popover should appear, and when they move their mouse away, the popover should disappear. Currently, I am using jQuery to achieve this functionality: $( ...

Exploring Angular 6's nested routes and corresponding components for child navigation

I'm currently diving into the concept of lazy loading in Angular 6. Here's a visual representation of the structure of my application: ─src ├───app │ ├───components │ │ ├───about │ │ ├─── ...

if jade is being inconsistent

I am currently using expressjs in my app and have the following setup: app.get('/profile',index.profile); app.get('/',index.home); Within layout.jade, I have the following code: ... if typeof(username)!=='undefined' ...

What is the best technique for vertically aligning text within two divs placed side by side?

Thank you for taking the time to read this. I have a piece of code similar to the one below. While using line-height works when there is only one line of text, it becomes problematic when the comments section contains multiple lines. I am wondering what w ...

The overlay of the background image is excessively oversized

After implementing the following CSS to showcase a background image: height: 90%; /* or any other value, corresponding with the image you want 'watermarked' */ width: 90%; /* as above */ background-image: url('<?php echo "study/".$_SESS ...

Is there a way to move the navbar to the right side of the screen?

How do I create a navigation menu that takes up half of the screen on the left side while allowing for scrolling on the right side without moving the navigation? What I am aiming for is similar to the images linked below: example example I attempted to u ...

Issue with the display of images

Is there a way to make a pop up image visible when hovering or clicking on an image on the webpage? Currently, the new pop up image is hidden behind the right div. Thank you in advance for any help. Paul ...

Include image hover text without using HTML

I am looking to add a hover effect to some images using CSS and JS since I cannot directly edit the HTML file. The goal is to have centered text pop out when hovering over certain images. I know the div class of the image but unfortunately, I cannot add te ...

Chrome's XPath attribute selection is not functioning properly

After running a small test with expect.js, here are the results: describe('xpath', function () { it('locates attribute nodes', function () { $(document.body).append('<string fooBar="bar"><data id="xyz">< ...

Using JQuery to handle click events on an array of checkboxes and displaying the value of the selected

I am struggling to show the label text and checkbox value from a checkbox array whenever each one is clicked (for testing purposes, assume I want it to appear in an alert). My HTML looks like this: <label class="checkbox"> <input type="checkbox" ...

What's the reason this picture isn't displaying in its full size?

I am having trouble adjusting the size of this image to fit the full width, but there seems to be some remaining space on the right side. Category: CSS/HTML /* Header */ .header { background: url('https://picsum.photos/1920/1080') center ...

What is the best way to remove input focus when clicked away?

I am in the process of developing an application using next js, and I need assistance with designing a search field. The primary functionality I am looking to implement is displaying search suggestions when the user starts typing, but hiding them when the ...

What is the best method for adding anchors or appending items in aspx pages?

I have created code for an image gallery on my webpage, "gallery.aspx". The situation is that I have an external aspx page with various links. When a user clicks on one of these links, I want them to be redirected to the image gallery but to a specific ima ...

Differences in tabstrip appearance between FireFox on Mac and Ubuntu compared to FireFox on PC

I've encountered an issue with my simple css tabstrip. It seems to render correctly in: Safari 5.0.2 on Mac IE8 on PC FireFox 3.8.12 on PC However, when viewed on FireFox 3.8.12 on Mac and Ubuntu, the tabs overlap the bottom border of the containe ...

A guide to using JavaScript to create a button that can dynamically change stylesheets

Just a heads up, I'm not using classes in this particular scenario. Can't seem to find the answer to this exact question. With javascript, how can I code a button to switch stylesheets every time it's clicked? I've experimented with d ...

In search of a render function that can effectively apply styles to HTML strings using React JS

I have been struggling to convert the result field value, including HTML attributes string, into respective styles for one column in my antd table. Below is the string I am trying to convert: The exhaust air requirements for fume hoods will be based on m ...

Incorporate External Web Page Information by Clicking a Button

Apologies if this question has already been asked, but despite my efforts to explore the available resources, I have not found a solution to my issue. I currently have an input field where users can enter their website, keyword, or industry. When they cli ...

Menu options disappearing upon clicking within the container area

Every time I click inside the dropdown menus, they unexpectedly close. This issue is persistent in both the Login menu and the nav bar. Although I’m not a seasoned web developer, I suspect it’s just a simple error that I’ve been overlooking all day ...