The inconsistency in div sizes may be attributed to the line-height setting

I'm trying to get two divs to sit next to each other and be aligned at the bottom. However, when I add a button and set the line-height, it drops slightly. See examples with images below.

My Desired Layout:

https://i.sstatic.net/MZQvg.png

Current Issue:

https://i.sstatic.net/IbRS2.png

You can see the issue in action on CodePen:

http://codepen.io/basickarl/pen/KVXqxR?editors=110

HTML Setup:

<div class="div1">
  hello<br>
  hello<br>
  hello<br>
  hello<br>
  hello<br>
  hello<br>
</div>
<div class="div2">
  <button class="butt">push meh</button>
</div>

CSS Styling:

.div1 {
  display: inline-block;
  background: red;
}
.div2 {
  display: inline-block;
  background: lime;
}
.butt {
  line-height: 40px;
  background: lightblue;
}

I've noticed that the text inside the button is causing alignment issues due to the line-height. Any suggestions on how to resolve this?

Answer №1

To align the elements at the bottom, add vertical-align:bottom to either .div1, .div2, or both:

.div2 {
  display: inline-block;
  background: lime;
  vertical-align:bottom;
}

View code example on CodePen

The default vertical alignment for inline elements is baseline, hence the current positioning.

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

What is the best way to add padding between form elements in Bootstrap 4?

Is there a way to add space between form elements in Bootstrap 4? The code snippet below shows an example where the full name has spacing from '@' but the username does not have any. Any suggestions on how to fix this? <form class="form-inlin ...

If the text is a single line, center it. However, do not center the text if it

Can we center align text horizontally if it occupies a single line, but refrain from center aligning and use white-space: normal when the text spans multiple lines (ideally without the need for JavaScript)? ...

Creating a flexible row layout in Bootstrap 4 that adapts responsively

Here is the current layout of the page: https://i.sstatic.net/KuHiT.png However, when resizing to a mobile screen, the flex boxes overflow the container: https://i.sstatic.net/kI3ee.png Html: <div id="bars" class="d-flex flex-row text-whi ...

Discover Vuejs: Display Less, Reveal More

In order to achieve a specific task, I need to display 12 items in 4 columns with 4 items each. Initially, only the first four items are visible and the rest are hidden until the user clicks the "Show More" button. Upon clicking the button, the next row ...

Integrate a PHP form that includes a redirect feature and an optional opt-in box

I'm a beginner and I'm trying to enhance this code by adding some extra features. When the form is submitted, I want the page to redirect to an external URL like www.google.com The checkbox should be automatically checked and when the client re ...

Retrieving a value from an input field within a table cell using jQuery

Looking for some help with a complex HTML Table structure like this one. <table id="items"> <tr class="total_up"> <td colspan="2" class="blank"></td> <td colspan="2" class="total-line">Total</td> ...

Challenges in achieving seamless interaction between Javascript Form and Ajax for logging in to a Secure Magento Store

My Webdeveloper abandoned me and my form doesn't seem to work always. When clicked it doesn't appear to do anything (just shows the "javascript:;" href on the browser status bar), but sometimes it works... I've searched everywhere for a so ...

Adding the BETA symbol to your Bootstrap navbar is simple and can be done by

Is there a way to include a "BETA" symbol at the top of the "Brand Name" on my Navbar, similar to the "TM" symbol? How can this be achieved? ...

A nimble framework designed to showcase HTML content developed

I currently have around 100 HTML pages generated by a python script, with the possibility of this number increasing significantly. Each page consists of 20 rows containing various text fields. These HTML pages need to be reviewed by a human for quality as ...

Newbie Question: What is the process to upload a website that consists of only HTML files to a web hosting provider

I'm embarking on creating a basic four-page website using HTML, CSS, and images. It's my maiden voyage into web design. When I finish developing the HTML files, what steps should I take to upload them and launch the website? ...

Changing the color of Material UI pagination: a step-by-step guide

I have integrated Material UI to create a pagination bar for my website. While everything is functioning properly, I am looking to personalize the appearance. After reviewing their documentation, I tried implementing a theme but encountered an issue with c ...

When YII_DEBUG is disabled, the CSS will not be implemented

My website is built using Yii along with YiiBooster. Everything works fine when I am in DEBUG mode - all styles load and apply correctly. However, when I set YII_DEBUG to false in the index.php file, the CSS files still show as loaded in Firebug, but it ap ...

Combine several svg elements within a single div row using Bootstrap 5

Is there a way to adjust the SVG settings in order to have two of them side by side within a div class="col" element? ...

What is the purpose of utilizing jQuery for retrieving CSS resources?

Upon reviewing the Chrome Dev Tools screenshot, I am puzzled by the fact that my CSS assets are being fetched by jQuery. The CSS sheet is included in the normal way, using a <link rel="stylesheet"> tag in the <head> section, while jQu ...

What is the best way to eliminate the space between <div> elements?

I am looking to arrange <div> elements in a specific layout where one is at the top, three are in the middle in a row, and one is at the bottom without any extra space. It is necessary that there remains a space between the middle <div>s and th ...

I am having an issue where my Bootstrap 4 col-sm-6 rows are not properly stacking on mobile devices

Currently facing issues with Bootstrap 4 as my columns are not stacking on top of each other in mobile view. I have two col-sm-6 within each row. Any guidance on how to resolve this would be greatly appreciated, thank you! Feel free to visit the website a ...

Personalized element IDs and unique CSS styles

After editing the code snippet below... <div id="rt-utility"><div class="rt-block fp-roksprocket-grids-utility title5 jmoddiv"> I applied the changes in my custom.css file like this: #rt-utility .rt-block {CODE HERE} However, when attemptin ...

What is the method for delivering a FastAPI response without causing the user to be directed to a different page?

I have developed an API using FastAPI that receives form-data from an HTML page, processes the data, and then returns a completion message after a short moment. Below is my backend code: from cgi import test from fastapi import FastAPI, Form, Request from ...

Concealing a section of a table with JavaScript while preserving the original table structure

I made some adjustments to the script tag: $(document).ready(function) { Now, the evenTd's are hidden correctly. Here is the table with the code provided: <table> <tr> <td>itemOne</td> <td class="even ...

What is the best way to increase the height of an image beyond the limits of its container, causing it to overlap with other elements

My challenge involves creating a horizontal scrolling list of movie posters. I want the posters to grow in size when hovered over, expanding outside of their container and overlapping other elements. I attempted to use 'position: absolute' on the ...