Is there a discrepancy in the display of inline-block content across various browsers?

My dilemma lies in the fact that I have a responsive form element that needs to be aligned inline with a title. Here is an example of what I'm aiming for: https://i.sstatic.net/2ckjf.png

Everything looks perfect in Firefox, just as I intended.
However, when viewed in Chrome (and similar results in Blisk, Yandex, and most webkit browsers, including MS Edge and IE11), this is the outcome:

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

This is the code snippet:

h1,
form {
  display: inline-block;
  vertical-align: middle;
}
h1 {
  font-size: 48px;
}
.field {
  display: table-cell;
}
.field,
input {
  width: 100%;
}
input,
.btn {
  padding: 10px 16px;
  box-sizing: border-box;
}
<h1>Inline title</h1>
<form action="">
  <div class="field">
    <input type="text" placeholder="Email Address" />
  </div>
  <div class="field">
    <button class="btn">Submit</button>
  </div>
</form>

Alternatively, please refer to the code on Codepen.io.
Do Firefox and Chrome interpret the CSS differently? It seems that Chrome is displaying the layout correctly due to the .field class having display: table-cell;, but I am uncertain. Is there a way to achieve the desired Firefox layout in Chrome without compromising the responsiveness of the input field?

Thank you.

Answer №1

To fix the issue, simply delete the property: table-cell and ensure that everything is set to inline-block:

h1,
form {
  display: inline-block;
  vertical-align: middle;
}
h1 {
  font-size: 48px;
}
.field {
  display: inline-block; /* replace table-cell with inline-block */
}
input,
.btn {
  padding: 10px 16px;
}

Check out the live demo here: CODEPEN

Answer №2

To achieve the desired layout, you can simply use float:left instead of table-cell and remove the width from the field class.

h1,
form {
  display: inline-block;
  vertical-align: middle;
}
h1 {
  font-size: 48px;
}
.field {
  float: left;/* Use float to align elements */
}
.field,
input {
  /*width: 100%;*/
}
input,
.btn {
  padding: 10px 16px;
}
<h1>Inline title</h1>
<form action="">
  <div class="field">
    <input type="text" placeholder="Email Address" />
  </div>
  <div class="field">
    <button class="btn">Submit</button>
  </div>
</form>

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

Adjusting the dimensions of images by using the percentage width and height relative to the body

On my website, I am displaying two images that are hosted on another company's server. To ensure these images adjust with the size of the browser window, I have set their width and height as a percentage relative to the body. However, the issue arise ...

Best practices for storing a HTML file in MongoDB

It seems that one of the benefits of using a document-oriented database such as MongoDB is its ability to store unstructured data effectively. For instance, when dealing with multiple HTML files, is it advantageous to have the entire content stored as a ...

Connecting MySQL to HTML: Step-by-step guide

I am currently working on building a website through coding in HTML using gedit. My goal is to have a login or registration feature on the homepage, which will then direct users to their own personalized page on the site. On this page, they should be abl ...

Deleting alternate child nodes from a DOM table while leaving other children untouched

I am currently programming in PHP and I have an HTML string that includes a table. My goal is to remove all the rows from the table, however, I am facing an issue where only every other row is being deleted. $html_string = <<<HTML <div class=&q ...

The issue of overflowing scroll functionality appears to be malfunctioning

.main-content{ height: 100%; width: 60%; min-height: 800px; background-color: white; border-radius: 5px; margin-left: 1%; border: solid 1px black; } .profile-banner{ display: flex; flex-direction: row; justify-content: space-between; ...

Tag - A guide on setting the required attribute for a tag

Currently, I am utilizing Jquery Tag it in order to manage tags and save the values in a database. My challenge lies in using jQuery to make the myTags field required, ensuring that at least one tag is added before proceeding with the save operation. This ...

The navigation bar has surpassed the content limit and overflow-y is visible

My website has a navigation bar with content that exceeds the desired limit, and I want the rest of the content to be shown in overflow-y. However, an issue arises when hovering over the content, as the content is displayed (likely due to fixing min-heigh ...

Does the onchange event differentiate between lowercase and uppercase letters?

Is the onchange event of the select tag case sensitive? Would it work if I use ONCHANGE instead of onchange? ...

The 'pageCreate' function in jQuery Mobile does not activate when revisiting a page

My scenario involves developing a web application for an embedded system user interface. I've decided to utilize jQuery Mobile due to its sleek features. The structure of my project follows a single page per file pattern, with one of the files being p ...

How to remove hover effect specifically from collapsed navbar in Bootstrap?

I created a webpage with a navigation bar that has links which scroll to different sections on the page. I added a hover animation to the links using the code below: .navbar-default .navbar-nav li a:hover, .navbar-default .navbar-nav li a:active { box ...

An image overlaying a background design featuring a navigation bar and company logo

Is there a way to stack images on a background image similar to this using HTML? There is also a navbar and logo on the background. I attempted to do something like this: //clearfix .image-stack::after { content: ' '; display: table; clear ...

Capture a section of the body background to incorporate into the canvas space

As a newcomer to the world of canvas, I have been learning from various sources about how it works. However, my goal is more dynamic and unique than what I've seen so far. I am looking to create a body background for my webpage that is responsive, cen ...

Is your Chrome DevTools changing CSS Link files to "Constructed Stylesheet" after you edit the CSS using Inspect Element? Find out how to fix this issue!

This issue relates to CSS files that are initially not identified as constructed stylesheets but end up being displayed as such after editing, rendering the file inaccessible. Specifically in Google Chrome DevTools (last observed in Chrome 86): Whenever ...

Integrate JavaScript with WordPress

How can I get this functioning properly within Wordpress? I have been attempting to connect everything together, but it doesn't appear to be working. Is this the correct way to do it, or am I overlooking something? <script type="text/javascript" s ...

Error: The property 'classList' cannot be read as it is null in Flask, jinja2, JavaScript, HTML, and Bootstrap

I am currently utilizing a bootstrap button class, and upon clicking the button, I pass this.id to the caretToggle() JavaScript function. Since I have multiple bootstrap buttons that I want to toggle the caret on, I attempted the method below, only to enco ...

Using the jquery plugin Sidr in Rails: A complete guide

I've been attempting to integrate the jQuery sidr plugin into my Rails project on Codecademy, but unfortunately, it's not functioning as expected. To view the page, simply click here: If you notice, the menu icon at the top left takes some time ...

Experiencing difficulties with the background color of a child div in HTML while using Yahoo

My dynamic "progress bar" component has the ability to render various background colors and widths based on different percentages. Here's a snippet of the code: <div style={{ backgroundColor: '#FFFFFF', height: '24px' ...

Personalize the behavior of input type=file

I currently have a file browser included on my webpage using the following code: <input type="file" /> My goal is to display a JavaScript "confirm" popup when the browse button is clicked. If the user clicks "OK" on the popup, then the file browser ...

CSS uses color parameters in the same way

Apologies, I spent a few years immersed in the world of IT. Now, onto my query: I have a lengthy ".css" file with numerous structures like color: #567567; within it. Is there a way to utilize a construction similar to color: $mycolor or is this not po ...

Unable to fetch the webpage element object

While attempting to extract data from the historical table on investing.com, I encountered an issue where I couldn't retrieve the column item and an error occurred. Traceback (most recent call last): File "<ipython-input-119-ba739f477693>", ...