Position form elements flush with div containers

.quantity-button {
height: 35px;
width: 35px;
padding-bottom: 1px;
margin-bottom: 3px;
font-weight: 600;
font-family: Raleway;
color: white;
background-color: #AA95B9;
border: 2px solid black;
border-radius: 5px;
cursor: pointer;
display: -webkit-flex;
display: inline-flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
vertical-align: middle;
}
#quantity {
text-align: center;
border: 1px solid black;
border-radius: 5px;
background-color: #C0B9C7;
height: 35px;
font-weight: 700;
vertical-align: middle;
box-sizing: border-box;
}
<div id="qtyWrap">
  <div class="quantity-button" onclick="decreaseQuantity();">
    < 
  </div>
  <input type="text" size="1" maxlength="1" value="1" name="quantity" id="quantity"/>
  <div class="quantity-button" onclick="increaseQuantity();">
    >
  </div>
</div>

There is a form field for quantity with two buttons that increment and decrement the value in the box. Despite attempts, I cannot get the alignment right, resulting in a vertical offset.

How can I ensure that the form element's height matches the buttons and align it so the top of the form element lines up with the top of the buttons?

Answer №1

Ensure that your input aligns with the divs by adding margin-bottom: 3px;:

(Alternatively, you can use vertical-align: top;)

.quantbutton {
height: 35px;
width: 35px;
padding-bottom: 1px;
margin-bottom: 3px;
font-weight: 600;
font-family: Raleway;
color: white;
background-color: #AA95B9;
border: 2px solid black;
border-radius: 5px;
cursor: pointer;
display: -webkit-flex;
display: inline-flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
vertical-align: middle;
}
#ppqty {
text-align: center;
border: 1px solid black;
border-radius: 5px;
background-color: #C0B9C7;
height: 35px;
font-weight: 700;
vertical-align: middle;
box-sizing: border-box;
}
<div id="qtyWrap">
  <div class="quantbutton" onclick="downQuant();">
    < 
  </div>
  <input type="text" size="1" maxlength="1" value="1" name="qty" id="ppqty"/>
  <div class="quantbutton" onclick="upQuant();">
    >
  </div>
</div>

Answer №2

When styling the element with the ID of #ppqty in CSS, experiment with the property vertical-align: top;

Here is an example:

#ppqty{
vertical-align: top;
}

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

Using a background image in CSS for horizontal rules can override other styling rules

Encountered an unusual CSS bug: After using background-image to style hr, none of the subsequent rules or selectors are displaying on the page: hr { border: 0; height: 1px; background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0 ...

How to load several stylesheets for a component in Angular 2

Struggling with my angular2 application, I encountered an issue when attempting to load multiple stylesheets for the same component. Below is a snippet of the code: import { Component } from '@angular/core'; @Component({ selector: 'my-tag& ...

Numerous textareas fail to function properly according to JQuery's standards

Need help with resizing multiple textarea elements dynamically as the user types in them (on the Y-axis). Currently, I have code that successfully resizes a single textarea, but it does not work when there are multiple textareas on the page. Here is the c ...

Components will be displayed without any gaps on smaller screens

I attempted to apply styles to two components in order to create space between them, visible on both larger and smaller displays. The code snippet appears as follows: <div> <CustomPageHeader pageTitle={t('offersPage.pageHeader')} ...

unable to display content from an external page within a DIV element

Here is the code I am using to load an external file inside a div: EXAMPLE <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.re ...

Is it secure to display my forms to the public eye?

Hello, I recently implemented a PayPal donation system on my website and used hidden form values to create buttons for donations. However, I realized that users could potentially view these values in the source code. Is there a security risk if someone see ...

Aligning a block heading in the middle of the page

I developed a basic flex-based table. section { display: flex; flex-direction: row; align-items: stretch; width: 100%; margin: 0; background-color: green; } h2, ul { width: 50%; padding-left: 1.5em; padding-right: 1.5em; } h2 { tex ...

The wrap() method in jQuery clones elements multiple times

I have created a simple function that wraps a div tag inside another div tag when the browser window exceeds a certain width of x pixels. However, I've encountered a strange bug when resizing the page more than once. Let me share with you the jQuery ...

What is the best way to insert a line break following a font awesome icon within a list?

My goal is to design a menu similar to LinkedIn's, featuring buttons made from icons positioned above text. However, I'm facing difficulty in inserting line breaks in CSS format after my FontAwesome icons. Despite having 'display:block' ...

Disable the dragging of a draggable div when another div is dropped inside

In my view, I have displayed reservations and tables as div elements. The tables are draggable and droppable, while the reservations are only draggable. My goal is to be able to drag a table to a desired position and then place a reservation on it. Once th ...

An issue arises when trying to loop using a while loop within an HTML structure

I have a small project with a predefined format, where I need to select a value from a dropdown menu and use that value to fetch data from a database and display it in HTML. While I am able to retrieve the data from the database based on the selected value ...

Using Python API to directly upload web files to Drive via URL

Currently working with the Drive REST v3 Python client library. I have successfully managed to upload files from my local machine to Google Drive. However, I am struggling to figure out how to upload files directly from the web to Google Drive using downlo ...

Improve the readability of a series of string.replace statements

When dealing with HTML code in Python, special characters need to be replaced using the following lines of code: line = string.replace(line, "&quot;", "\"") line = string.replace(line, "&apos;", "'") line = string.replace(line, "&amp ...

Converting HTML to PDF on iOS devices

I've encountered a challenge with a large HTML file that contains dynamically changing data. My goal is to convert this HTML document into a PDF format and send it as an email attachment. Can anyone offer advice on how I can accomplish this task? ...

The execution of the code may encounter errors initially, but it generally runs without any issues on subsequent attempts

I recently developed a piece of code to ascertain whether a value in the database is null or not. Here's the snippet: var table; var active = false; function CheckActive(table){ this.table = "table" + table + ""; var db = window.openDatabas ...

Paper.js: Is there a way to prevent canvas height and width from changing when the window is resized?

My canvas with paperjs is set up to resize dynamically when the window is resized. I appreciate any help in advance. HTML <canvas id="myCanvas" height="800" width="1000"></canvas> JS var Initialize = function () { var canvas = document ...

Form tag abruptly disappears in Chrome inspector

As I delved into someone's .asp code, I stumbled upon a concerning discovery - an unclosed HTML tag. To unravel this mystery, I turned to Chrome and its inspector tool only to find the missing tag right there in front of me! Puzzled, I returned to th ...

Embracing New and Returning Users with Jquery Cookies: A Guide on Making Every User Feel Welcome

I'm currently working on setting up a Welcome page for both new and returning users using cookies with jQuery. However, I've encountered an issue where upon submitting the form with new user data, the message displayed is not "Welcome New User," ...

How can I integrate checkboxes in a list view with jQuery Mobile?

How can I display the status of users with three different levels in a list view? I need to show whether they are attending or not, similar to the image provided. The issue is that currently the checkbox appears below the name, but I want it to be at the r ...

Navigating through a HTML email Listserv with a click event scrolling feature

I am looking to create an interactive HTML email with a link that can scroll the recipient's browser to a specific section within the email. I am considering using Javascript and jQuery for this functionality. Can someone guide me on how to implement ...