简体   繁体   English

如何修复 textarea 边框底部 css 效果?

[英]How can I fix the textarea border bottom css effect?

I have a simple border bottom animation with another element and it works fine on simple input element but it's not work properly on a textarea.我有一个简单的边框底部 animation 和另一个元素,它在简单的输入元素上工作正常,但在文本区域上不能正常工作。 (If I should use javaScript then please advise a solution) (如果我应该使用 javaScript 那么请提供解决方案)

How can I fix the height of textarea?如何修复textarea的高度?

 *{ box-sizing: border-box; }.container { position: relative; } textarea, input { border: none; border-bottom: 3px solid #e6e6e6; width: 100%; height: 50px; resize: none; }.anim-bar { position: absolute; bottom: 0; left: 0; height: 3px; width: 0%; background-color: blue; -webkit-transition: width.3s; transition: width.3s; } textarea:focus +.anim-bar, input:focus +.anim-bar { width: 100%; }
 <h1>Works fine on input:)</h1> <div class="container"> <input type="text"> <span class="anim-bar"></span> </div> <h1>Cross the container box- textarea:( </h1> <div class="container"> <textarea></textarea> <span class="anim-bar"></span> </div>

this issue not show on all browsers.此问题并非在所有浏览器上都显示。 in my browsers chrome(window) is obvious.在我的浏览器中 chrome(window) 很明显。

the line is under textarea.该行位于textarea下。

在此处输入图像描述

====================================================== ==================================================== ====

I think is baseline is different.我认为基线是不同的。

Baseline inconsistency基线不一致

The HTML specification doesn't define where the baseline of a is, so different browsers set it to different positions. HTML 规范没有定义 a 的基线在哪里,所以不同的浏览器将它设置到不同的位置。 For Gecko, the baseline is set on the baseline of the first line of the textarea's first line, on another browser it may be set on the bottom of the box.对于 Gecko,基线设置在 textarea 第一行的第一行的基线上,在另一个浏览器上它可能设置在框的底部。 Don't use vertical-align: baseline on it;不要在其上使用垂直对齐:基线; the behavior is unpredictable.行为是不可预测的。

reference:参考:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

 * { box-sizing: border-box; }.container { position: relative; } textarea, input { border: none; border-bottom: 3px solid #e6e6e6; width: 100%; height: 50px; resize: vertical; /* see this */ vertical-align: middle; }.anim-bar { position: absolute; bottom: 0; left: 0; height: 3px; width: 0%; background-color: blue; -webkit-transition: width.3s; transition: width.3s; } textarea:focus+.anim-bar, input:focus+.anim-bar { width: 100%; }
 <h1>Works fine on input:)</h1> <div class="container"> <input type="text"> <span class="anim-bar"></span> </div> <h1>Error on textarea:( </h1> <div class="container"> <textarea></textarea> <span class="anim-bar"></span> </div>

================================================== ====================================================

Adding CSS styling to the textarea resize: none;将 CSS 样式添加到textarea resize: none; will stop the textarea from being adjustable.将阻止textarea可调整。

I added the styling to the CSS area and inline the HTML to show both ways it can be done.我将样式添加到 CSS 区域并内联 HTML 以显示可以完成的两种方式。

 * { box-sizing: border-box; }.container { position: relative; } textarea { resize:none; //adding styling in css file } textarea, input { border: none; border-bottom: 3px solid #e6e6e6; width: 100%; height: 50px; resize: vertical; }.anim-bar { position: absolute; bottom: 0; left: 0; height: 3px; width: 0%; background-color: blue; -webkit-transition: width.3s; transition: width.3s; } textarea:focus+.anim-bar, input:focus+.anim-bar { width: 100%; }
 <h1>Works fine on input:)</h1> <div class="container"> <input type="text"> <span class="anim-bar"></span> </div> <h1>Error on textarea:( </h1> <div class="container"> <textarea style="resize:none;"></textarea> <!--Adding CSS styling inline--> <span class="anim-bar"></span> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM