Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input text with dashed border and stroke length equal to the characters

Tags:

html

css

How do I make an input text using CSS, with a dashed bottom border/line that the length of strokes are equal to the length of each character?

Here's an example:

enter image description here

like image 814
Nuno Almeida Avatar asked Dec 03 '25 00:12

Nuno Almeida


2 Answers

Try using border-bottom: 1px dashed black;

like image 124
Akshay Gundewar Avatar answered Dec 04 '25 14:12

Akshay Gundewar


dashed border style doesn't give the exact effect because we cannot control the length of strokes. Instead, we can make the dashed border by using an absolutely positioned pseudo-element behind the input, and specify the space between strokes by letter-spacing property.

input[type="text"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: 0;
  outline: 0;
  background: transparent;
  width: 12.70em;
  font-size: 1em;
}

.input-wrapper, input[type="text"] {
  font-family: monospace;
  font-weight: bold;
  letter-spacing: .3em;
}

.input-wrapper {
  display: inline-block;
  position: relative;
  overflow: hidden;
  padding-bottom: .2em;
  font-size: 200%;
}

.input-wrapper:after {
  content: "——————————————————————————————";
  line-height: .3em;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: -1;
}
<div class="input-wrapper">
  <input type="text" value="Hello World" maxlength="15">
</div>
like image 33
Hashem Qolami Avatar answered Dec 04 '25 16:12

Hashem Qolami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!