Aligning a button and textbox to have equal heights side by side

Is there a way to update the default form styling for two form elements so that the text box and button have the same height and are positioned side by side to create the illusion of one element?

While it appears correctly in some browsers, in others they seem to be vertically misaligned by a pixel or two. I'm having trouble with Opera and Firefox on OS X specifically. Here is a demo on jsfiddle: http://jsfiddle.net/QS3ec/6/

*, *:before, *:after {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
input[type="text"] {
    background-color: #fafafa;
    padding: 7px;
    font-family: helvetica, arial, sans-serif;
    font-size: 1.2em;
    margin-bottom: 20px;
    display: block;
    border: solid 2px #bbb;
    color: #6f6f6f;
} 
...
(remaining code remains unchanged)
...

Answer №1

One solution is to adjust the CSS rule below:

#subscription-email-text-field {
    vertical-align: top;
    display:inline-block; 
    font-size:0.9em; 
    font-weight:400; 
    border:0; 
    width:250px;
    height:32px;
    margin:0;
}

By adding vertical-align: top, you can ensure proper baseline alignment.

View a demonstration here: http://jsfiddle.net/audetwebdesign/EmAnr/

Note:

If you want to include a left border on the button element, make sure to add the appropriate border styling with the following code:

#subscribe-button {
    display:inline-block;
    border: 1px solid black;
    border-width:0px 0px 0px 1px;
    margin:0;
    height:32px;
}

Answer №2

I have made a simple adjustment to the height of the submission box:

height: 46px;

Check out the updated submission box here.

After testing in Safari, Firefox, Opera, and Chrome on Mountain Lion, it appears that this solution may not be definitive.

It seems that the issue lies in the fact that the inputs are unconventional elements rendered by the browser using methods other than CSS, which may result in unexpected styling outcomes. I encountered a similar dilemma in the past, shedding light on such behavior patterns when attempting to style old UI components like buttons or inputs.

Explore more about Display Table Cell inconsistency here.

Answer №3

One issue is the padding applied to the text box, which can have varying effects across different browsers. Specifically, some browsers may only apply horizontal padding to input types like buttons or submit forms.

To address this, you can add a 'box-sizing: content-box' rule within the closure of input[type='submit'] {}. This fix may work on certain browsers where it has been implemented.

If you encounter issues with vertical padding, consider setting the height of the submit button to be equal to the height of the text box plus twice the padding applied to the text box. This method ensures consistency in appearance across various browsers.

For example, if the text box height is 32px and the padding is 7px, the button height would be calculated as follows: 32 + (2 * 7) = 46px

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

CSS3 :target and display:none inconsistency problem in Internet Explorer and Firefox

Creating a one-page site with navigation tabs that toggle between hidden divs using :target CSS3 selector is my current project. To ensure the first div is visible upon page load, I implemented this line of code: document.location.href = "#div1"; The HTM ...

What is the best way to line up a label and a textarea?

Here is how my code currently looks: XXXXX XXXXX Description: XXXXX My desired output is: XXXXX Description: XXXXX XXXXX Sometimes the "Description" field can span multiple lines. Code snippet: < ...

adjust the size of a form field to match the background image dimensions

I'm encountering an issue while trying to solve this particular challenge: My goal is to integrate a login box onto a full-screen image. Although I've come across numerous methods for incorporating an image into a form field, my task requires me ...

Utilizing border-radius specifically on the ul element to apply rounded corners to only the outer li items

I'm exploring a concept where I want to create a curved border around the list items, both on the outside and inside. Here are some examples: Right Check out the correct curved border here Wrong: See the incorrect curved border here Please note, ...

Ways to emphasize the currently active tabs on a navigation bar

How can I highlight the active tabs and shift it when clicking on another link? $(function() { $('.nav ul li').on('click', function() { $(this).parent().find('li.active').removeClass('active'); $(this).a ...

Deactivating The Canvas Element

I am currently working on a project that involves using Three.js alongside a menu placed above the canvas element, which is essentially a regular div. However, I have encountered an issue where the canvas element still registers input when interacting with ...

What would be the best way to display a label once the zoom level exceeds a certain threshold in Leaflet?

As someone new to the Leaflet library and JavaScript in general, I'm currently facing a challenge with showing/hiding a leaflet label based on the zoom level. The markers are within a 'cluster' layer loaded via AJAX callback, and I bind the ...

A guide on how to perfectly center a <ul> element on a webpage

After creating a ul element, I have customized the html and css for my navigation bar: Html: <ul id="list-nav"> <li><a href="Marsrutas.html">Item1</a> </li> <li><a href="Nuotraukos.html">Item2</a& ...

Creating an AI adversary for a simple Tic Tac Toe game board: a step-by-step guide

Being new to programming, I recently completed a basic Tic Tac Toe gameboard successfully. However, as I progress to the next phase of my assignment which involves implementing an AI opponent, I encountered several challenges. As a novice in programming, ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

Create a text container that adjusts its size based on the content within

My goal is to create a unique display using CSS: I want to add various texts and lines to fill in the white space on the left and right sides. I have made some progress with this http://jsfiddle.net/g5jtm/, but I am facing a few issues: The text width ...

Take a break in between keyframe animations

I have a basic animation set up with keyframes. @-webkit-keyframes rotation { 0% { -webkit-transform: rotate(10deg); } 25% { -webkit-transform: rotate(5deg); } 50% { -webkit-transform: rotate(10deg); } 75% { -webkit-transform: ...

The menu item fails to respond to clicks when hovering over the header background image

I'm having an issue with the Menu Link not working. I can click on the menu item when it's placed inside the body, but when I try to place it over the background header image, it stops working. Any help would be greatly appreciated. <div clas ...

Conceal or style the filter panel in a DT datatable

Here is an example to consider: library(DT) L <- 10 datatable( data.frame( var1 = sapply(1:L, function(x) paste("<X>",paste0(x, letters, LETTERS, "\n", ...

A versatile CSS and JavaScript slider component that is designed to be reused multiple times within a single webpage

Looking to create a CSS/jQuery slider that can be used multiple times on one HTML page. I have a client who wants sliders as category links, but I'm struggling to get it working as a single slider on a page. Can someone review the code and point out ...

What steps are involved in creating a table using Bootstrap framework?

Hey there! I need your expertise on how to create a specific layout using bootstrap: codepen.io/anon/pen/bqJdQJ <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div cl ...

Display a switch icon based on input created by the user

I've been struggling to implement a toggle button for user-generated input, specifically using a Font Awesome toggle button. Here is the link to my codepen: http://codepen.io/lucky500/pen/bdpzbd along with the code snippet: <div id="list" class= ...

Adjust the <div> element to dynamically resize based on the user's browser changes

I need a div to adjust its width and height dynamically based on the browser dimensions when a user resizes their browser window. Implemented code following the provided suggestions: <!DOCTYPE html> <html> <head> <link rel="s ...

How can I create a dashed border around a <div> element using HTML and CSS?

On Stack Overflow, I noticed that there are many DIV elements surrounded by dotted lines. How can this be achieved using CSS and HTML? Thank you, Bin ...

Guide to inserting an icon within an input field

Seeking assistance in placing the checkmark icon inside the input box at the right corner. Additionally, I would like to know if it's feasible to show a 'Field Saved' message alongside the tick icon? Update: If the form contains multipl ...