Jurģis Toms Liepiņš Jurģis Toms Liepiņš - 1 year ago 76
HTML Question

Make a span act like an input field when overflowing

I am duplicating my input field value in a span which is placed directly on top of the input field. (Doing this to manipulate only part of the text)

I am having problems with the overflow.

Currently if I continue typing past the limit of the input field, the span will just expand infinitely. enter image description here

Is there a way, to have the span act like the input field would and scroll the text to the left as more and more characters are added?

Current span styling:

style="display: inline-block; position: absolute; top: 0.25px; left: 2px; padding: 1px; z-index: 2; pointer-events: none;"


EDIT

<div style="position: relative;" class="input-box">
<input style="color: transparent; caret-color: black; z-index: 1;" type="text" name="street[]" id="street_1" class="street
input-text"/>

<span id="street1span" class="input-text" style="display: inline-block; width: 100%; position: absolute; top: 0.25px; left: 2px; padding: 1px; z-index: 2; pointer-events: none;" ></span>
</div>

Answer Source

Try This :

span {
    border: 1px solid #CCC;
    width: 200px;
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
}

input[type="text"] {
    width: 200px;
}
Span :<span contenteditable="true"></span>
<br><br>
Input:<input type="text" name="">

After Edit your Post :

span {
    position: absolute;
    top: 100px;
    left: 2px;
    padding: 1px;
    z-index: 2; 
    border: 1px solid #CCC;
    width: 200px;
    height: 20px;
    display: inline-block;
    white-space: nowrap;
    overflow: hidden;
}
<div style="position: relative;" class="input-box">
    <input style="color: #000; caret-color: black; z-index: 1;" type="text" name="street[]" id="street_1" class="streetinput-text"/>

<span id="street1span" contenteditable="true" class="input-text" >
    </span>
</div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download