Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome number field horizontal scroll

I created a number field which has the text inside aligned to the right.

UseCase:

If you select the full text or when you use your middle mouse button inside of the input field to scroll I noticed that it is possible to scroll the text for about 1px to the left. So far I could only provoke this behavior in Chrome.

You can see it in action with this code:

<input type="number" value="15" style="text-align: right;" />

Solution:

I could probably disable the scrolling on the element but I wanted to ask you if there is an elegant way to fix this.

Here you can see the code: http://codepen.io/anon/pen/mEmAvz

like image 339
pluga Avatar asked Jun 30 '16 14:06

pluga


People also ask

How do I get rid of the horizontal scroll bar in Chrome?

2. Type "Remove Scrollbars" (without quotes) in the search box and press "Enter." Click the "Remove Scrollbars" option located on top of the search results.

What is causing horizontal overflow?

An overflow issue occurs when a horizontal scrollbar unintentionally appears on a web page, allowing the user to scroll horizontally. It can be caused by different factors. It could occur because of unexpectedly wide content or a fixed-width element that is wider than the viewport.

How do I find out what is causing horizontal scroll?

To find out which elements cause a horizontal scrollbar, you can use the devtools to delete elements one by one until the scrollbar disappears. When that happens, press ctrl/cmd Z to undo the delete, and drill down into the element to figure out which of the child elements cause the horizontal scrollbar.


1 Answers

You could use text-indent with calc. Like so:

html {
 box-sizing: border-box;
}

*, *:before, *:after {
 box-sizing: inherit;
}

input {
  width: 100%;
  text-indent: calc(100% - 1.5em);
  font-size: 1em;
}

https://jsfiddle.net/VilleKoo/u2ead3gz/1/

like image 116
VilleKoo Avatar answered Oct 19 '22 04:10

VilleKoo