Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove a bottom border on input textfield, under the new char?

I just received this visual design:

enter image description here

CLG is a label tag, while the line is an input type=tel Just ignore the purple overlay...

The designer asks me to remove the border as the user types a new number.

Is that possible?

like image 960
Matteo Avatar asked Jul 28 '15 08:07

Matteo


People also ask

How do I remove the default border around a text field?

Also, you can remove the default borders on certain sides by setting them to "transparent". See another example where the outline: none; is set for <input>, <textarea> and <select> fields.

Why does my textfield have a border at the bottom?

When you add a TextField in your NativeScript app, by default it has no border on iOS, but on Android, there is a persistent border at the bottom. This is part of material design and it comes out of the box in NativeScript.

How to remove textfield text input bottom underline in flutter Android iOS?

TextField widget has a property decoration which has a sub property border: InputBorder.none .This property would Remove TextField Text Input Bottom Underline in Flutter Android iOS mobile app. The bottom underline shows us how much area in width Text Input is occupying on mobile screen. 1. Import material.dart package in your app’s main.dart file.

How do I remove the border around an outline in HTML?

Remove the outline and add a border style using the :focus and :active pseudo-classes with the <input> field. You can also remove the default borders on specific sides by setting them to "transparent".


2 Answers

It is definitely possible, however it includes

  • JavaScript (for checking the current input size)
  • Flexbox (for auto-shrinking the border)

The idea is basically to mimick the border with a :after pseudo-element and shrink it to the remaining width of the <label>.

// https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
[].forEach.call(document.querySelectorAll('input'), function(element) {
  element.addEventListener('input', function() {
    element.size = element.value.length;
  });
});
label {
  display: flex;
  align-items: stretch;
  font-weight: bold;
}
label:after {
  content: '';
  display: block;
  width: 100%;
  border-bottom: 1px solid gray;
}
input {
  display: block;
  border: none;
}
<form>
  <label>CLG <input type="tel" size="1"></label>
</form>
like image 199
Dominik Schreiber Avatar answered Sep 28 '22 20:09

Dominik Schreiber


Instead of input element, I used a div element with contenteditable property.

.wrapper {
    border-bottom: 1px solid black;
    width: 250px;
    height: 25px;
    white-space: nowrap;
}
.wrapper > div {
    display:inline-block;
    vertical-align: middle;
    height: 100%;
}
.text {
    position: relative;
    min-width:10px;
}
.text:after {
    content:"";
    border-top: 1px solid white;
    border-bottom: 1px solid white;
    top: -1px;
    bottom: -1px;
    left: 0px;
    width: 100%;
    position: absolute;
}
.text:focus {
    outline: none;
}

Working Fiddle

like image 32
Mr_Green Avatar answered Sep 28 '22 19:09

Mr_Green