Align the submit button to be centered with the form box

I've been struggling to properly align my submit button with a form entry. What I want is for the submit button to be centered slightly to the right of the form box. Currently, it's aligned to the right but positioned a bit lower than desired.

Despite trying various solutions like using floats and margins as suggested in similar questions, I just can't seem to find the perfect option!

My HTML code looks like this:

<input name="query" id="querybox" style="width:400px;height:40px;font-size:26px;border-radius:15px;border=0;">
        </input>

    <input type="button" value="Search" id="search" style="width:100px;height=40px;font-size=20px;"/>

The CSS used to style the button is as follows:

    #search {
cursor:pointer; 
    width:70px; 
    height: 31px; 
    line-height:0; 
    font-size:0; 
    text-indent:-999px;
    color: transparent;  
    background: url(ico-search.png) no-repeat #151B54 center; 
    border: 1px solid #FFFFFF; 
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px; 
}

#submit:hover {
    background: url(ico-search.png) no-repeat center #151B54; 
    border: 1px solid #FFFFFF;

    }

Any assistance would be greatly appreciated! Thank you.

Answer №1

To ensure your inputs are aligned correctly, enclose each of them within a div element:

<div class="vertAlign">
    <input name="query" id="querybox" style="width:400px;height:40px;font-size:26px;border-radius:15px;border=0;"></input>
</div>

<div class="vertAlign"> 
    <input type="button" value="Search" id="search" style="width:100px;height=40px;font-size=20px;"/>
</div>​

Next, apply the following CSS styling:

.vertAlign{
    display: inline-block;
    vertical-align:middle;
}​

Check out this JSFiddle link for a visualization of the result.

Please note that your existing CSS should work fine, but has been omitted from the provided example for clarity purposes.

Answer №2

Check out this interactive code example:

http://jsfiddle.net/UXRjN/1/

I enclosed the search button within a DIV element and included some extra attributes for enhancement.

Answer №3

To vertically align inline elements within a line, utilize the vertical-align CSS property.

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

Flex wrap is causing additional space within the layout

When using flex-wrap, if there are more textBoxes than the available width in the container, they shift to the next line. This is fine, but it leaves too much space between the button and the textBox. This spacing issue can make the layout look odd. I hav ...

The utilization of getPreventDefault() is obsolete; defaultPrevented should be used instead in Angular JS

Trying to learn AngularJS has been a challenge for me, as I can't seem to get it to work properly on my system when using code from their documentation. The error message that keeps popping up is: The use of getPreventDefault() is deprecated. Please ...

PHP code for sending email with attachment file

I have created an HTML form with the option to upload a file and send it to me via email. Additionally, I already have a PHP script that sends textbox values and text area values via email. Now, I would like the uploaded file from the form to be sent to m ...

Refreshing information within a table using Ajax Prototype

For my current project, I am utilizing PrototypeJS. I have implemented Ajax.PeriodicalUpdater to insert real-time data as required. However, I am facing an issue where the data is not getting replaced inside a specific table. Below is the HTML code snippet ...

The height of EasyAutoComplete is restricted by the designated div height

I am experiencing an issue with my EasyAutoComplete feature that displays City & PostalCode information. The problem lies in the height of the div containing the input field, which limits the visibility of the EasyAutocomplete window. Only the first elemen ...

iOS and Phonegap now feature vertical swipe and drag screens for seamless navigation

Can I implement a vertical swipe screen transition in Phonegap like the Facebook app for notifications? I want to have 5 main pages in my app, but also be able to swipe left to see a separate page with notifications and calendar items. Just confirming if ...

Retrieving information from an API and incorporating it into JSX results in displaying text within the HTML element

I have retrieved data from an API with the following response: { "name": "family: woman, woman, girl, girl", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F467", "html": "&#128 ...

How can I use Bootstrap and jQuery to automatically resize the container class to a smaller size when the sidebar is activated?

After enhancing this question and adding more code to my example, I decided to repost it in a better form. However, despite wanting to delete this one, the instructions advise against it. If you're interested, feel free to check out my revised questi ...

Changing color of navigation bar link upon refreshing the page using Bootstrap

I am new to the world of HTML/CSS/Bootstrap and recently made a change to the color of a link on the navbar. However, I am encountering an issue where the original blue color of the link briefly appears when I refresh the page. I would like to prevent this ...

What is the best way to ensure that hashtag links function properly in Internet Explorer?

This guide provides step-by-step instructions on how to implement CSS3 modal windows. It is designed to function smoothly on Chrome and Firefox browsers, although Internet Explorer may have trouble loading links with hashtags. Tutorial Demo The first li ...

A step-by-step guide on integrating a Django template tag and HTML element into an HTML page using Javascript

Is there a safe way to insert HTML that includes Django template tags using JavaScript in my project? For instance, if my template contains the following code: <div id="some-element"> <span id="my-tag">{{ my_data }}</sp ...

Is it possible to retrieve the selected DataList object in Angular 10?

I encountered an issue while creating an Input field with DataList. My goal was to retrieve the entire object associated with the selected option, but I could only access the selected value. Previous suggestions mentioned that DataList items should be uniq ...

Can lines be visually represented within this specific div element?

I have a challenge where I am rendering data into a single div and I am exploring the possibility of using CSS to create three lines between the four columns. Even though it would be easier if I used separate columns with borders, I prefer the flexibility ...

Tips for keeping your navigation menu fixed at the top of the page as you scroll

I successfully created a navigation menu using ul > li. Currently, the menu is positioned in the center of the page. My goal is to make the menu stay at the top of the page only while scrolling. I know I can achieve this using css .menu { positi ...

Loading HTML div content on demand using AngularJS

I have been working on a project where I retrieve data from the server to update the data model on the client browser using one-way data binding. The structure of the data model is outlined below. In relation to this data model, I am displaying the conten ...

Having issues with the JavaScript voting system {{bindings}} returning null when clicked?

It seems like the error is not appearing in the developer tool, so it might be related to how the data is being read. Both {{upVote}} and {{downVote}} start with no value and show null when clicked, indicating that the buttons are somehow linked. I was att ...

Trigger sound playback when button is pressed in SwiftUI

Is there a way in SwiftUI to play an audio file as soon as a button is clicked, rather than waiting for the touch release event? How can I achieve this functionality? Here is a snippet of my code: struct PressedButtonStyle: ButtonStyle { let touchDown ...

Manipulating the visibility of a template with ng-show and ng-hide

Is it possible to use ng-show and ng-hide in order to display or hide an HTML template, particularly if that template is a separate HTML file? I am attempting to divide my HTML file into two sections and toggle their visibility based on an event. ...

Having difficulty getting the h1:after element to properly float to the left and center

I am facing an issue with the styling of a :after class that creates a line under a floated h1 element. The h1 element is floated left, and I want to center the :after line underneath it. Despite floating it left and attempting a text-center on the parent ...

Display a JSON file within an Angular application using HTML

I have a JSON (link to the JSON) that I want to display in an html file. JSON: { "recipes": { "FRYING": { "Anchovies": [ [ {"500": "thawing"} ], [ {"60": "nothing"} ] ], "Codfis ...