What could be causing the submit button on this form to not be centered by this CSS?

I have been attempting to center this submit button using CSS, however, despite researching various online resources, I have not yet discovered a solution. It seems strange that such a simple task is proving to be so challenging.

td.class > div {
  width: 100%;
  height: 100%;
  overflow: hidden;
  height: 20px;
}
#buttonstyle {
  border: 2px solid #777777;
  background: #019966;
  color: black;
  font: bold 18px'Trebuchet MS';
  padding: 4px;
  cursor: pointer;
  width: 150px;
  border-radius: 12px;
  display: inline-block;
  margin: 0px auto;
}
.buttonHolder {
  text-align: center;
}
.heading {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  color: #006633;
}
input {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 10px;
  font-weight: normal;
}
input[type=text] {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: normal;
}
input[type=date] {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: normal;
}
ul {
  list-style: none;
  text-align: left;
}
input {
  width: 20px;
  position: relative;
  left: 150px;
  vertical-align: middle;
}
label {
  width: 200px;
  position: relative;
  left: -20px;
  display: inline-block;
  vertical-align: middle;
}
<form name="InstructorForm" action="../instructorDB_protected/instructorDB_controller.php" method="post" enctype="multipart/form-data">
  <div id='content'>
    <center>
      <span class="heading">Colorado Mountain Club - Boulder Group Instructor Database<br>Instructor Administrator Export Form</span>
      </p>
      <p>
        Select which schools to export to a file to download.
        <br>The file will contain a list of instructor names, emails and phone numbers:
        <p>
          <div id="yourdiv" style="display: inline-block;">
            <ul>
              <li>
                <input type="checkbox" name="avi_instructor">
                <label>Avalanche:</label>
              </li>
              <li>
                <input type="checkbox" name="hiking_instructor">
                <label>Hiking:</label>
              </li>
              <li>
                <input type="checkbox" name="ice_instructor">
                <label>Ice:</label>
              </li>
              <li>
                <input type="checkbox" name="rock_instructor_trad">
                <label>Rock, Trad:</label>
              </li>
              <li>
                <input type="checkbox" name="rock_instructor_sport">
                <label>Rock, Sport:</label>
              </li>
              <li>
                <input type="checkbox" name="ski_instructor">
                <label>Ski:</label>
              </li>
              <li>
                <input type="checkbox" name="snow_instructor">
                <label>Snow:</label>
              </li>
            </ul>
          </div>
          <br>
          <div class="buttonHolder">
            <input id=buttonstyle type="submit" name="submitAdminExport" value="Export">
          </div>
          <br>
          <a href="../instructorDB_protected/instructorDB_top.php" target="_self">Return to top</a>
    </center>
  </div>
</form>

Despite my attempts at removing other CSS files in order to troubleshoot, the submit button continues to resist being centered and instead aligns itself along the right margin of the checkboxes above it in the list. Any assistance on resolving this issue would be greatly appreciated!

Answer №1

Simply remove the left property from the input

#buttonstyle{
      left: auto; 
}

This is what you have provided here

input{
     width:20px;

     position:relative;
     left: 150px; 

     vertical-align:middle; 
}

Alternatively, you can write it like this

input:not(#buttonstyle){
      width:20px;

      position:relative;
      left: 150px; 

      vertical-align:middle; 
}

It would be more elegant to exclude your button styles from the input styles :)

Also, a helpful hint for you: use web developer tools in the future to see what styles are applied to specific elements. In 99% of cases, you can solve your problems by inspecting the styles applied.

I hope this helps you, cheers

Answer №2

The alignment issue stems from the left property on the input.

Replace the current code with this:

#yourdiv input{
    width:20px;

    position:relative;
    left: 150px; 

    vertical-align:middle; 
}

This change ensures that the left: 150px; property only affects input elements within the #yourdiv div.


Check out the solution on jsFiddle: https://jsfiddle.net/AndrewL32/e0d8my79/101/

Answer №3

It all boils down to one simple thing: the position:relative property...

Make sure to adjust your button code as follows:

<input id="buttonstyle" type="submit" name="submitAdminExport" value="Export" style="position: static;">

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

Trouble displaying REACT.jsx in browser

I'm currently learning React and struggling to get it running smoothly. HTML function Person(){ return ( <div class="person"> <h1>Max</h1> <p>Your Age: 28</p> </div> ); } ...

Implementation of multiple angular guards causing a crash on the page

I have been attempting to implement separate guards for distinct pages. Essentially, I am checking a boolean parameter to determine if a user is logged in or not. Below are the two guard.ts codes that I am using: export class IsAuthenticatedGuard implemen ...

How to align several lines of text in a table cell

I've been trying to center multiple lines of text in a table cell using the table method, but no matter how many online guides and SO posts I follow, I just can't seem to get it right. What I'm aiming for is to have the text perfectly cente ...

How can you achieve three layers of nested quotes in Dynamic HTML?

Working on an app that utilizes JQuery and JQTouch for iOS. The issue I'm facing involves dynamically generated HTML lists where the user clicks a row that needs to be highlighted. However, achieving this has proven tricky due to nesting 3 sets of quo ...

Issues with aligning text in TextBoxes

I'm struggling to center align my text boxes and write labels on either side. I want it to look like this: https://i.stack.imgur.com/6QsNv.png Despite trying different solutions, I can't seem to get the boxes to align in the center. Is there a ...

Spacing Issue with Material UI Gap Placement

Currently, I am implementing Material UI 5 within a React project using the following code snippet: <Stack> <Stack flexDirection="row" justifyContent="center" padding={4} spacing={{ xs: 4 }} ...

What's Going on with My Angular Dropdown Menu?

Snippet of HTML code: <li class="nav-item dropdown pe-3"> <a class="nav-link nav-profile d-flex align-items-center pe-0" (click)="toggleProfileMenu()"> <img src="assets/img/profile-img.jpg" alt=& ...

"Exclusive Mui sx styles will be applied only when a specific breakpoint

As I update my old mui styling to utilize the sx attribute, I've noticed the ability to specify styles for different breakpoints using sx = {{ someCssProp: { xs: ..., md: ... and so on. Prior to this, I had been using theme.breakpoints.only for some ...

Is there a way to incorporate CSS into an element utilizing jQuery when only a class is available for identification, and when the time in the innerHTML is within a 5-minute range from the current time?

I have some HTML code that I need help with: <td class="mw-enhanced-rc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;18:10&nbsp;</td> My goal is to use JavaScript to make the time bold. $('td[class^="mw-enhanced-rc"]').eac ...

Gin and Golang: Implementing HTML files with CSS styling

I am still learning English, so please bear with me :) My issue is that when using Gin to load HTML, my HTML file contains an import (/stylesheet/index.css), but when I run my app with Gin, it gives an alert that the stylesheet file could not be loaded. ...

Mobile Website Blog Page With Dual Sidebars Issue

I have created a blog page using bootstrap 4 that features both left and right sidebars along with the main content section. Everything looks great on Desktop view. However, when viewed on a mobile phone, the order changes to: left-sidebar>content> ...

"Setting up a filter for the first row in an Excel-like table using a pin header

Does anyone know how to create a table filter in Excel where the header and first row stay pinned while scrolling down, even after applying filters? Here is a JSFiddle demonstrating the issue: http://jsfiddle.net/6ng3bz5c/1/ I have attempted the followi ...

Set the class of the list item to "active" class

My approach to styling involves using a UL and li class to contain form selection options. I plan on hiding the radio button and using its value upon form submission. I have managed to enable checking the radio box when the <li> is clicked, but for s ...

Is there a way to stop all HTML5 videos except for the one that I want to watch?

On my webpage, I have three HTML5 videos all on one page. My goal is to be able to pause or mute all the videos at once, except for the one that I specifically choose. Initially, I tried using an event listener on the parent div which worked well when clic ...

TextBox with MultipleLines

I'm looking to add functionality to a text area with formatting capabilities as shown in the diagram. Can anyone guide me in the right direction? Also, whenever I click on the text area, a formatting tool should automatically appear above it. This i ...

Get the HTML file converted to a DOCX format that is compatible with Mac Pages

I am currently working on a Next.js application using TypeScript, and I want to give users the ability to download a page as a DOCX file. Initially, I was excited to discover that this could be easily accomplished by following this method. However, after ...

Alter the Color of the 'div' According to the Background

At the bottom right of my website, there is a black chatbot icon. The web footer also has a black background. To create a clear contrast, I have decided to change the color of the chatbot to white as users scroll to the bottom of the page. I implemented t ...

Converting HTML to plain text using the DOMDocument class

Is there a way to extract the text content from an HTML page source code, excluding the HTML tags? For example: <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="hu"/> <titl ...

Tips for embedding HTML/CSS snippets in backticks when using TypeScript with AngularJS

Does anyone else experience the issue of their Angular 2 templates showing up as gray text in Visual Studio Code? I'm unable to use autocomplete or see my CSS properly. Is this a settings problem or is there a plugin that can solve this? BTW, I am us ...

Steps to Show an Image When Hovering and Clicking on the Relevant Div

CSS: .imgECheck { position: absolute; top: 0; right: 5px; width: 15px; height: 15px; display: none; } .imgFCheck { position: absolute; top: 0; right: 5px; width: 15px; height: 15px; display: none; } Is ther ...