The alignment of flex items is not consistent in Webkit browsers

One of the issues I am facing involves a text field that contains a cogwheel symbol which opens a popup menu with different search options. The layout is set up using a flexible box model for certain elements.

After testing in Firefox, the display is as expected:

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

However, when viewed in Webkit browsers such as Safari and Vivaldi, the layout appears like this:

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

The main problem I am encountering is that the cogwheel is not aligned properly in Webkit browsers. Although the text menu not stretching can be fixed by adjusting the container width, the misalignment of the cogwheel is my primary concern.

Though I do not currently have Chrome, I suspect it may exhibit similar rendering issues as other Webkit browsers.

Below is the relevant CSS code that I believe is contributing to the problem:


.flex-search {
  position: relative;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: stretch;
  align-items: stretch;
  width: 100%;
  border: 1px solid #222;
  border-radius: .4em;
  background-color: #fff;
}
.flex-search > :first-child {
  -webkit-flex: 1;
  flex: 1;
}
.flex-search > :last-child {
  width: 2em;
  border-left: 1px solid #ccc;
  cursor: pointer;
}

Here is a snippet that demonstrates the search field in its entirety:


$( '.flex-search input[type="radio"]' ).click( function() {
  $( this ).closest( 'span' )
    .css( 'display', 'none' )
    .delay( 500 )
    .queue( function ( next ) {
    $( this ).removeAttr( 'style' );
    next();
  } );
  $( this ).closest( 'fieldset' )
    .find( 'input[type="text"]' )
    .attr( 'placeholder', $( this ).closest( 'label' ).text() )
    .focus();
} );

/* CSS Snippet */

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <fieldset class="flex-search">
    <span>
      <input type="text" name="id" placeholder="contains">
    </span>
    <span>
      <span>
        <label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
        <label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
        <label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
        <label><input type="radio" name="t-id" value="i"><span>equals</span></label>
      </span>
    </span>
  </fieldset>
</div>

I am seeking insights into why the Webkit browsers are displaying the layout differently and what steps I can take to rectify this issue. If you have suggestions on simplifying the code, that would also be greatly appreciated, but my primary focus is on achieving a consistent display across all browsers.

Answer №1

The reason the cogwheel ends up on the second line is due to a webkit bug that fails to render fieldset elements as a flexbox container

Check out this list of flexbugs that highlights the same issue: Some html elements cant be flex containers

To resolve this issue, you can add a div as an inner wrapper.

<fieldset>
  <div class="flex-search">
    ....
  </div>
</fieldset>

Here is a snippet from Stack Overflow:

$('.flex-search input[type="radio"]').click(function() {
  $(this).closest('span')
    .css('display', 'none')
    .delay(500)
    .queue(function(next) {
      $(this).removeAttr('style');
      next();
    });
  $(this).closest('fieldset')
    .find('input[type="text"]')
    .attr('placeholder', $(this).closest('label').text())
    .focus();
});
(CSS code here)
(JavaScript code here)

Answer №2

You mentioned that the span should have a padding-left of 30%, resulting in insufficient space for the text. Simply remove the 30% and it should work correctly. You can also consider adding .8em as a fourth parameter, but most browsers will handle this automatically for you.

.flex-search label>span {
  position: relative;
  display: block;
  font-size: 85%;
  text-align: right;
  padding: .2em .8em .2em; <-- 30% removed
}

<!-- JavaScript code here -->
<!-- CSS code here -->
<!-- HTML code here -->

Update: If the intention behind the 30% padding was to create enough space for the check mark, you can replace it with 2em:

.flex-search label>span {
  position: relative;
  display: block;
  font-size: 85%;
  text-align: right;
  padding: .2em .8em .2em 2em;
}

<!-- JavaScript code here -->
<!-- CSS code here -->
<!-- HTML code here -->

By incorporating the solutions from LGSon and this one, the final result should look like this:

<!-- JavaScript code here -->
<!-- CSS code here -->
<!-- HTML code here -->

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

Importing images in React for CSS does not function properly

I've encountered an issue while trying to import an image for CSS. I successfully imported the image and used it in the img tag as src={furnitureBG} for testing purposes. Following the documentation, I imported the image and set the path as the value ...

Utilizing pure JavaScript to dynamically fetch HTML and JavaScript content via AJAX, unfortunately, results in the JavaScript

I am trying to load an HTML file using AJAX and then execute a script. Here is the content of the HTML file I want to load: <div class="panel panel-body"> <h4>Personal Data</h4> <hr /> <span data-bind="editable: firs ...

Attention! Are you aware of the potential consequences of the impending phase-out of the name attribute in W3C validation? Have you considered how this development

Any thoughts on what could replace the name attribute? According to the W3C validator... Validation Output: 4 Warnings Here is a list of the warning message(s) generated while checking your document. Warning Line 12, Column 21: The name attribute i ...

Why are the UI components (`Card Number`, `MM/YY`, `CVC`) not being displayed in the React app when using Card

Having an issue where the CardElement Ui component is not visible in the image provided. It should appear above the Order Total: $0 next to the payment method. https://i.sstatic.net/NCK5z.png I've attempted various debugging methods without success. ...

What's the deal with inline blocks and text in the middle?

Check out this code I created for a navigation bar. HTML : <div class="header-nav"> <div class="header"> <img src="../Pictures/LifeFrame/2.jpg" width="100%" height="100px" /> </div> <div class="nav" align="c ...

Tips for achieving a design aesthetic similar to that of the JQuery UI website

On my website, I am using jQuery UI along with the "Smooth Default" CSS theme. However, I have noticed that everything appears larger compared to the jQuery UI website itself. For instance, when looking at the buttons here: http://jqueryui.com/button/ The ...

Create a full-width slider using Materialize CSS framework

When using materializecss to create a slider, I encountered an issue where the image is full width but not full height, causing scrollbars to appear. What changes can I make to ensure the slider fills out my screen without any scrollbars? Additionally, I ...

How can you prioritize one CSS file over another?

To avoid repetition, I wish to have all the classes, tags, and ids from css.css take precedence over bootstrap.min.css, without duplicating any from bootstrap.min.css. <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/css.css ...

Show a picture upon hovering the button

Welcome to my website. My goal: Show an image when a user hovers over the links. I must be making some silly error, but I can't pinpoint it. This is what I've attempted so far: HTML <ul class="nm"> <li><a href="#">Cork& ...

unable to decrease the gap between the rows of the table

I'm currently developing an application that involves a table with rows and columns, along with a checkbox container arranged as shown in the image below: https://i.stack.imgur.com/QoVrg.png One issue I'm facing is getting the letters A, B, C, ...

Arrange the child elements of a div to be displayed on top of one another in an HTML document

I am struggling with a div containing code .popupClass { width: 632px; height: 210px; position: absolute; bottom:0; margin-bottom: 60px; } <div class="popupClass"> <div style="margin-left: 90px; width: 184px; hei ...

Differences in CSS between IE10 and Chrome are causing compatibility issues

Website in question: What is causing the difference in display between IE 10 and other browsers? The website appears to function correctly on Chrome: IE 10: ...

Guide to using jQuery to load an image

I am using this code to load an image and display it within a dialog box. <div id="image_preview" title="Client Photo Preview"> <p><img src="" alt="client image" id="client_image_preview" /></p> </div> $("#client_image_p ...

Searching for and substituting text in HTML

I am using basic HTML without any Javascript, XML, CSS, etc. I am trying to locate instances of "--" and replace them with an 'em dash'. Below is the code I have written: <!DOCTYPE html> <html> <center> <head> <tit ...

Can HTML be rendered within classes?

In the admin section of a website, I am working with multiple CRUD tables that require displaying success, information, or error messages when certain actions are performed, like deleting a record. This is a common practice that involves wrapping messages ...

the stacking context of elements with z-index and relative positioning

I am currently working on a modal that is toggled using JavaScript. Within the modal, I am dynamically adding an image using JavaScript. Additionally, there will be a div element overlaying the image to simulate cropping (extract coordinates from the imag ...

The choice always seems to gravitate towards the initial option without any clear explanation

echo "<td>Language</td>"; echo "<td><select id='language' name='language'> <option value=''>Select...</option> <option value='en_US'>English(US)</o ...

What methods can be used to customize the font and background color of a website for different user groups?

Trying to incorporate a template into my project. My client has requested the following: The regular user area should feature a blue background. The professional user area should have an orange background. Is there a way to set up a condition to change ...

Template Function Problem Detected in AngularJS Formatting

I'm struggling to incorporate my scope attributes into a template function within my custom directive. The formatting for the return section in my template is not working as expected. This is how it currently looks: angular .module(' ...

Exclude a specific link from a JQuery function

Check out this unique single page site that utilizes a waypoint script for navigation and highlighting nav items - The functionality works seamlessly, however, we are facing an issue where we need to modify a link to redirect to an external website. Unfor ...