As MrLister pointed out, max-height
and min-height
, expressed in em
, seems to be your best bet. I use it frequently on production systems and haven't had any complaints:
function updateInputs() {
$("input").each(function() {
$('span', $(this).parent()).remove();
$('<span />', {
text: $(this).outerHeight()
}).appendTo($(this).parent())
});
}
$('#fontSizer').on('input', function() {
$('body').css('font-size', $(this).val() + 'px');
updateInputs();
});
$(window).on('load',updateInputs);
body {
font-size: 16px
}
input {
font: inherit;
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
border: 1px solid silver;
padding: 0.5rem;
margin: 0;
max-height: 2.25em;
min-height: 2.25em;
}
[type="search"] {
-webkit-appearance: textfield;
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
background-color: silver;
}
.fixed-top {
background-color: rgba(255, 255, 255, .85);
display: flex;
align-items: center;
justify-content: center;
top: 0;
width: 100%;
left: 0;
position: fixed;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Input Heights</h1>
<p><input type="text" placeholder="text"></p>
<p><input type="search" placeholder="search"></p>
<p><input type="tel" placeholder="tel"></p>
<p><input type="url" placeholder="url"></p>
<p><input type="email" placeholder="email"></p>
<p><input type="datetime" placeholder="datetime"></p>
<p><input type="date" placeholder="date"></p>
<p><input type="month" placeholder="month"></p>
<p><input type="week" placeholder="week"></p>
<p><input type="time" placeholder="time"></p>
<p><input type="datetime-local" placeholder="datetime-local"></p>
<p><input type="number" placeholder="number"></p>
<!-- <p><input type="range" placeholder="range"></p> -->
<!-- <p><input type="color" placeholder="color"></p> -->
<p><input type="submit" value="submit"></p>
<div class="fixed-top">
<input type="range" step="0.01" id="fontSizer" max="54" min="10" value="16">
</div>
Note the range slider only changes the font-size
on <body>
(and updates the size displayed, accordingly).
A completely different approach is to increase the padding value for the normal ones so they reach the same size as the ones having spinners. The closest I got to something decent is
:root {
--input-padding: 0.5rem;
}
input {
padding: calc(var(--input-padding) + .1475em) var(--input-padding);
line-height: 1.225em
}
input[type="date" i], input[type="datetime-local" i], input[type="month" i], input[type="time" i], input[type="week" i] {
padding: var(--input-padding)
}
function updateInputs() {
$("input").each(function() {
$('span', $(this).parent()).remove();
$('<span />', {
text: $(this).outerHeight()
}).appendTo($(this).parent())
});
}
$('#fontSizer').on('input', function() {
$('body').css('font-size', $(this).val() + 'px');
updateInputs();
});
$(window).on('load',updateInputs);
body {
font-size: 16px
}
input {
font: inherit;
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
border: 1px solid silver;
margin: 0;
}
[type="search"] {
-webkit-appearance: textfield;
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
background-color: silver;
}
.fixed-top {
background-color: rgba(255, 255, 255, .85);
display: flex;
align-items: center;
justify-content: center;
top: 0;
width: 100%;
left: 0;
position: fixed;
}
:root {
--input-padding: 0.5rem;
}
input {
padding: calc(var(--input-padding) + .1475em) var(--input-padding);
line-height: 1.225em
}
input[type="date" i], input[type="datetime-local" i], input[type="month" i], input[type="time" i], input[type="week" i] {
padding: var(--input-padding)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Input Heights</h1>
<p><input type="text" placeholder="text"></p>
<p><input type="search" placeholder="search"></p>
<p><input type="tel" placeholder="tel"></p>
<p><input type="url" placeholder="url"></p>
<p><input type="email" placeholder="email"></p>
<p><input type="datetime" placeholder="datetime"></p>
<p><input type="date" placeholder="date"></p>
<p><input type="month" placeholder="month"></p>
<p><input type="week" placeholder="week"></p>
<p><input type="time" placeholder="time"></p>
<p><input type="datetime-local" placeholder="datetime-local"></p>
<p><input type="number" placeholder="number"></p>
<!-- <p><input type="range" placeholder="range"></p> -->
<!-- <p><input type="color" placeholder="color"></p> -->
<p><input type="submit" value="submit"></p>
<div class="fixed-top">
<input type="range" step="0.01" id="fontSizer" max="54" min="10" value="16">
</div>
However, it's not perfect. The errors are not linear and I suspect there's some rounding involved. Sometimes it goes above, sometimes below.
min-height:1em; max-height:1em;
, or is that cheating? – Granulationinput[type='date'] {padding-top:4px;}
– Granulation