CSS 实现 textArea 的 placeholder 换行
2016-03-18 10:50
573 查看
textArea的placeholder不能换行。例如:
这是不会起作用的,会原封不动地输出。
官方不认为这是一个bug:
The placeholder attribute represents a short hint (a word or short phrase)
For a longer hint or other advisory text, the title attribute is more appropriate.
意思就是说placeholder表示的是一个简单的提示(一个词或者一个短语),根本不需要换行。如文本太长,那就用title。
但是实际应用中,我们有时需要换行。如何解决?很多时候我们用JavaScript来解决,其实CSS也可以实现。
由于placeholder属性是可以用css操作的,所以我们可以用:after来把placeholder的内容写到CSS中,曲线救国。
以上是webkit的代码,Firefox类也有相应的版本:
<textarea placeholder="第1行 \n 第2行 <br> 第3行 \A 第4行 第5行"></textarea>
这是不会起作用的,会原封不动地输出。
官方不认为这是一个bug:
The placeholder attribute represents a short hint (a word or short phrase)
For a longer hint or other advisory text, the title attribute is more appropriate.
意思就是说placeholder表示的是一个简单的提示(一个词或者一个短语),根本不需要换行。如文本太长,那就用title。
但是实际应用中,我们有时需要换行。如何解决?很多时候我们用JavaScript来解决,其实CSS也可以实现。
由于placeholder属性是可以用css操作的,所以我们可以用:after来把placeholder的内容写到CSS中,曲线救国。
textarea::-webkit-input-placeholder:after{ display:block; content:"line@ \A line#";/* \A 表示换行 */ color:red; };
以上是webkit的代码,Firefox类也有相应的版本:
textarea::-moz-placeholder:after{ content:"line@ \A line#";/* \A 表示换行 */ color:red; };
相关文章推荐
- Web布局连载——两栏固定布局(五)
- [div+css]晒晒最新制作专题推广页模板
- 盒子模型
- CSS选择器
- CSS样式优先权
- [css] line-height 百分比单位和数值单位的区别
- Apple官网研究之使用Justify布局导航
- 设计更快的网页(三):字体和 CSS 调整
- 纯CSS制作的新闻网站中的文章列表
- 10条影响CSS渲染速度的写法与使用建议第1/3页
- BS项目中的CSS架构_仅加载自己需要的CSS
- 很不错的 CSS Hack 又学了一招
- 发一个css比较清爽的写法
- CSS expression控制图片自动缩放效果代码[兼容 IE,Firefox]
- css布局网页水平居中常用方法
- CSS经典技巧十则第1/2页
- css 兼容性问题this.style.cursor=''hand''
- IE6不能正常解析CSS文件问题的解决方法及原因分析
- 欲练CSS ,必先解决IE的一些细节分析
- CSS文字截取功能实现代码