Problem
Since Chrome 76 absolutely positioned inline elements with no bottom
, left
, right
or top
properties are being placed differently.
Example
View the snippet below in Firefox (69) and Chrome (76+). Chrome will display the button
and span
on a new line, while Firefox will display them next to the label
.
div {
margin: 2em auto;
position: relative;
}
input {
width: 100%;
}
button,
span {
position: absolute;
}
<div>
<label for="text_field1">Example with button</label>
<button>BUTTON</button>
<input type="text" id="text_field1" value="Example value">
</div>
<div>
<label for="text_field2">Example with span</label>
<span>SPAN</span>
<input type="text" id="text_field2" value="Example value">
</div>
Expected behaviour
The button
/span
should be placed next to the label
, not below it. It appears that Chrome is changing the display
mode from inline-block
/inline
to block
(see https://www.w3.org/TR/css-position-3/#dis-pos-flo) before it calculates where to place the element whereas Firefox and older versions of Chrome do this the other way around.
Chrome 76 (Unexpected behaviour)
Chrome 75 (Expected behaviour)
Firefox 69 (Expected behaviour)
Edge 16 (Expected behaviour)
Safari 12 (Expected behaviour)
Browsers effected
Any Chromium based browser since version 76.
Is this a bug or an intentional change to how Chromium will position elements under these conditions?
How can we position the element in a consistent manner across browsers?