2017-08-17 34 views
2

我在直接放置在输入字段顶部的跨度中复制输入字段值。 (这样做只能操作部分文本)溢出时使跨度像输入字段一样起作用

我遇到了溢出问题。

目前,如果我继续输入超过输入字段的限制,跨度将无限扩展。 enter image description here

有没有办法让跨度像输入字段一样行动并随着越来越多的字符添加滚动文本到左侧?

电流量程造型:

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

编辑

<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> 

回答

2

试试这个:

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="">

编辑您的帖子后:

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>

+0

在他的情况下,如果没有内容可编辑的,但用于演示目的,这是完美的解决方案。 – Doomenik

+0

这是完美的,但在我的网站上,它不会很好地回滚,就像在这里的代码段中,文本在输入字段的末尾消失 –

+0

这可能是因为我的跨度不是'contenteditable =“true”'? –

0

,你可以在你的跨度添加overflow-x:auto;

1

试试这个:

* { 
 
    font-family: Arial, sans-serif; 
 
    font-size: 12px; 
 
} 
 
input { 
 
    display: inline-block; 
 
    position: absolute; 
 
    top: 0.25px; 
 
    left: 2px; 
 
    padding: 1px; 
 
    overflow-x:auto 
 
    }
<div class="row"> 
 
    <input type="text" placeholder="something span" /> 
 
</div>

+1

这仍然只是一个输入字段 – Doomenik

0

你可以做

HTML

<span id="flow"></span> 

CSS

.flow{ 
    overflow : hidden/auto; // depending on your choice 
} 
-2

试试这个:

<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"/> 
    <br /><br /><br /> 
    <hr /> 
    <span id="street1span" class="input-text" style="display: inline-block; width: 100%; padding: 1px; border:1px solid #ccc; width:300px; overflow-x:scroll;" > hellhellhellhellhellhellhellhellhellhellhellhellhellhello</span> 
</div> 
+1

任何解释,你有什么建议? –

+1

一个很好的答案应该包括文字说明你做了什么以及你为什么做了,用户做错了什么? –