Looking for assistance with aligning a form in the center?

After spending the last hour trying to center a form for a name without success, I have decided to seek help here. Although I have searched extensively, I am still struggling at this point.

Here is my HTML:

<div id="main" class="main">
    <table border="0" class="container1">
        <tr>
            <td>
                <p>
                    <img src="images/doesitfit.png" />
                </p>
            </td>
        </tr>
    </table>
    <table border="0">
        <div class="container2">
            <input type="text" value="Enter Your First Name" id="form" onblur="javascript:if(this.value=='')this.value='Enter Your First Name';" onclick="javascript:if(this.value=='Enter Your First Name')this.value='';"></input>
        </div>
    </table>
</div>

Below is my CSS:

.main {
    background-color: rgba(11, 11, 11, 0.8);
    width: 800px;
    height: 550px;
    border-radius:15px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    margin-left: auto;
    margin-right: auto;
    min-height: 10em;
    height:100%;
    overflow:hidden;
}
.container1 {
    table-layout: fixed;
    height:50%;
    overflow:hidden;
    width: 802px;
    border-color:#ff0000;
    border-radius:15px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    margin-left: auto;
    margin-right: auto;
    min-height: 10em;
    color:white;
    margin: auto;
}
.container2 {
}
#form {
    font-size: 19px;
    border: 0px solid;
    color: #7a7a7a;
    height:28px;
    width:295px;
    text-align:center;
    margin: auto;
}

I also intend to include additional forms (inputs) such as Email and phone number.

Thank you in advance for any assistance provided. I truly appreciate it.

Answer №1

Check out my CodePen demonstration on how to center the input field: (http://codepen.io/kevingimbel/pen/BKruj)

The main issue here is that applying margin: 0 auto; will not work unless the input is set to display:block;. Additionally, it's recommended not to use <table> for layouts - opt for <div> instead.

I have provided comments in the CSS within the Pen. If you require further assistance, feel free to ask and I will monitor this thread for some time. I hope this information proves helpful.

Answer №2

Give this a shot:

form {
margin-left:auto;
margin-right:auto;
}

Answer №3

To properly style your input, enclose it within a form element and remove the # symbol before "form" in CSS.

<form>
  <input type="text" value="Enter Your First Name" onblur="javascript:if(this.value=='')this.value='Enter Your First Name';" onclick="javascript:if(this.value=='Enter Your First Name')this.value='';">></input>
</form>

form {
  font-size: 19px;
  border: 0 solid;
  color: #7a7a7a;
  height: 28px;
  width: 295px;
  text-align: center;
  margin: 0 auto;
}

If you prefer to keep the input ID as "form"

<input type="text" value="Enter Your First Name" id="form" onblur="javascript:if(this.value=='')this.value='Enter Your First Name';" onclick="javascript:if(this.value=='Enter Your First Name')this.value='';">></input>

#form {
  display: block;
  font-size: 19px;
  border: 0 solid;
  color: #7a7a7a;
  height: 28px;
  width: 295px;
  text-align: center;
  margin: 0 auto;
}

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

Is there a way to implement hover behavior for a Material-UI Button within a ButtonGroup component?

When using MUI v5, I am encountering an issue where the first button in the code provided is only half working. The button is initially colored red (both the border and text), however, upon hovering over it, the color of the border changes to blue. This is ...

Opera and Internet Explorer have trouble properly applying css text-decoration

It appears that the CSS text-decoration style is not being correctly displayed in Opera 11 and IE 9, but works perfectly fine in Chrome, Firefox, and Safari. Can anyone offer a solution to fix this issue? Incorrect Rendering: Correct Rendering: Below is ...

Incorporating orientation settings within a media query using MUI

In my current project, I am utilizing MUI in conjunction with React. To specifically style the iPad resolution using MUI breakpoints, I have implemented the following code snippet: contentBox:{ width:"10%", paddingLeft:"10p ...

Learning the process of extracting Fast Fourier Transform (FFT) data from an audio tag within

I am struggling to retrieve the FFT data from an <audio> tag without any syntax errors. After reviewing the Web Audio API documentation, I have written a sample code snippet as follows: <audio id="aud" controls="controls" src="test.mp3"></a ...

Scraping Information on Pokemon from the Web

I am currently researching the number of moves each Pokemon from the first generation could learn. After some exploration, I came across a helpful website that provides this information: The website lists 151 Pokemon, and for each of them, their move set ...

importing a text file into the appropriate input field on an HTML form

I've been experimenting with this JavaScript code and I can't seem to get it to work as intended. The code is designed to save the value of a single textbox into a text file that can later be loaded back into the same textbox. However, I'm f ...

"Troubleshooting: jQuery Find function not functioning correctly with HTML template

I am having trouble with a Shopify liquid code that I am trying to load into an HTML template <script type="text/template" id="description"> <div class="product-ddd"> {{ product.description }} </div> ...

Establish a comprehensive background for your Angular project

I've been struggling to figure out how to set a background image for my entire angular project. I've tried using global css and the app.component.css file, but it only sets the background for the component area. Here is a snippet from my global ...

transforming a table into a stylized CSS design

Seeking assistance in converting a table into CSS as I am new to CSS: <table dir="ltr" width="500" border="0" align="center"> <caption><font face="Helvetica">Movies</font></caption> <colgroup width="50%" /> ...

I am interested in building a personalized flight search form on my WordPress site

Currently, I'm in the process of developing a website for an aviation company. The WordPress site has been completed and uploaded to their hosting service. However, the client has requested that I create a custom search form and link it to their booki ...

Tips for aligning a single item to the center in a Bootstrap navigation bar that has the majority of items on the right

I am attempting to center the text "Welcome:" within the navbar without center aligning the entire navbar. I want the navbar to remain right aligned, but only the "Welcome:" portion should be centered. Here is what I have tried so far... <!DOCTYPE html ...

Customizing the appearance of Indicators and Paginator in PrimeNG Carousel

I have integrated a carousel using PrimeNG which has the following design here Take note of the style of the carousel indicators and navigators. I want to achieve the default style of indicators/navigators for the carousel as shown here I have included t ...

Creating a new object store in IndexedDB on Windows 8

Encountering issues with creating an object store in IndexedDb while trying to build a Metro app using Javascript. The code snippet below shows my attempt within the 'dbReq.onsuccess' function that is supposed to create the object store upon succ ...

"Utilize Selenium to navigate and select a menu option with a

In my dropdown menu, I am trying to use Selenium to move the mouse to the Documentation menu item and click on the App Configuration option within it. The mouse hover function is working properly, but I am unable to click on the App Configuration element. ...

The alignment of Bootstrap Select dropup with search results is off

I've encountered an alignment issue with bootstrap select live search (selectpicker). The dropup menu is misaligned when showing search results, but strangely, the alignment corrects itself after scrolling the page. Interestingly, this issue doesn&apo ...

What is the best way to ensure a floated image matches the height of its parent container?

I am facing an issue with setting the height of a logo within a footer div to match the height of the div itself. Using height: 100% doesn't seem to work as expected. Below is the relevant HTML: <footer> <img src="images/circle_logo.png" ...

Copying content from one website to another using JavaScript

Currently, I am working on a website which stores data and I require assistance in transferring this data to another site. If you have any suggestions using Javascript or other methods, please let me know. ...

Is there a way to include a textarea or text input in a table row and have it expand upon clicking or dragging, without increasing the row height?

I am looking for a way to allow a textarea to expand or grow when clicked or dragged, without affecting the height of the table row it is in. You can see an example of the issue on this CodePen: https://codepen.io/kerastensorflow/pen/PobaRvK?editors=1010 ...

Choose the div without a class

I currently have several divs displayed on my website. <div class="slide bx-clone"></div> <div class="slide"></div> <div class="slide"></div> <div class="slide bx-clone"></div> <div class="slide bx-clone" ...

Position tables on the right side of adjacent tables

There are two tables named id="BFCategories" and "BMICategories". Additionally, there are two other tables with id="BFTable" and "BMITable" BFCategories should come after BFTable, while BMICategories should follow BMITable. How can I a ...