2017-05-05 57 views
0

我已经计数器放置在文本区域的右上角用CSS:部队空间

position: absolute; 
    @include right(pxToRem(5)); 
    bottom: pxToRem(45); 
    font-family: $font-family-regular; 
    color: $text-color-grey-8; 
    font-size: $font-size-12; 

与HTML:

<textarea 
placeholder{{translationService.translate('REPORT_ADD_COMMENT')}}" 
ngControl="comment" #comment="ngForm" 
[attr.maxlength]="maxLengthReportPost"></textarea> 
<span class="form__textarea-counter">{{showCharCounter()}}</span> 

CSS的textarea的:

min-height: pxToRem(80); 
line-height: pxToRem(21); 
padding-top: pxToRem(3); 
padding-right: pxToRem(13); 

作为开始打字和接近柜台的结果是非常接近柜台甚至在它作为 enter image description here

我怎么能强迫spsce计数器和文本之间的 enter image description here

请不jQuery的

+0

欢迎的StackOverflow,你的问题应该包含一个[**最小的,完整的和可验证的实例**](http://stackoverflow.com/help/mcve)。 FWIW,你基本上不能用'textarea'。你必须用常规元素创建你自己的textarea小部件,然后你可以做一些事情。 – hungerstar

回答

0

你可能会发现这是很有帮助的,我知道这是不是100%,充分证明,但可能是它可以帮助你

textarea{ 
 
    resize: none; 
 
    width: 100%; 
 
    max-width: 100%; 
 
    max-height: 100%; 
 
    padding-right: 20px; 
 
} 
 
span{ 
 
    position: absolute; 
 
    bottom: 5px; 
 
    right: -15px; 
 
} 
 
.textarea-holder{ 
 
    position: relative; 
 
    width: 200px; 
 
}
<div class="textarea-holder"> 
 
    <textarea> 
 
    </textarea> 
 
    <span>11</span> 
 
</div>

+0

谢谢,我已经试着去做了,但问题是所有的行都会离结尾的eadg很远,我试图想方设法不让文字太接近那么多,只是从柜台 但是谢谢 – Hadeel36

0
经过多次意见

完全改变了答案:

不要使用position: absolute的柜台,但要display: inline;float left代替,并删除容器的heigth,并把它放入容器中的最后一个元素:

.x1 { 
 
    position: relative; 
 
    background: #ccf; 
 
    width: 400px; 
 
    overflow: hidden; 
 
    border: 1px solid #222; 
 
} 
 
.x2 { 
 
    float: right; 
 
    display: inline; 
 
    background: #fff; 
 
    width: 50px; 
 
    height: 20px; 
 
    border-left: 1px solid #555; 
 
    padding-left: 10px; 
 
}
<div class="x1">asd kja bsd lkj zg kjh iuz kj huz j hjg iuz kjh ku jhg kjh lkj iuz jh kjh iu kj l asd asd asd asd sd asd asd kja bsd lkj zg kjh iuz kj huz j hjg iuz kjh ku jhg kjh lkj iuz jh kjh iu kj l asd kja bsd lkj zg kjh iuz kj huz j hjg iuz kjh kuz j hjg iuz kjh ku jhg kjh lkj iuz jh kjh iu 
 
    <div class="x2"> 
 
    counter 
 
    </div> 
 
</div>

+0

padding-left not working与位置:绝对......谢谢你 – Hadeel36

+0

是的,这是 - 看这里:https://codepen.io/anon/pen/aWLXJo(也可能所有其他填充,但在这个例子中,我只使用填充左) – Johannes

+0

是的,但是这个解决方案并不干净,你不能只隐藏在柜台下面的文本......但是再次感谢你:) – Hadeel36