亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用CSS實(shí)現(xiàn)textArea中的placeholder換行功能

segmentfault   發(fā)布時(shí)間:2015-07-08 18:22:01   作者:weakish   我要評論
這篇文章主要介紹了用CSS實(shí)現(xiàn)textArea中的placeholder換行功能,依照傳統(tǒng)方法書寫的話會出現(xiàn)問題,文中給出了解決方法,需要的朋友可以參考下

textArea的placeholder不能換行。例如:

<textarea placeholder="第1行  \n 第2行 <br> 第3行 \A 第4行
第5行"></textarea>

這是不會起作用的,會原封不動地輸出。
201578182418610.jpg (450×300)

官方不認(rèn)為這是一個(gè)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表示的是一個(gè)簡單的提示(一個(gè)詞或者一個(gè)短語),根本不需要換行。如文本太長,那就用title。

但是實(shí)際應(yīng)用中,我們有時(shí)需要換行。如何解決?很多時(shí)候我們用JavaScript來解決,其實(shí)CSS也可以實(shí)現(xiàn)。

由于placeholder屬性是可以用css操作的,所以我們可以用:after來把placeholder的內(nèi)容寫到CSS中,曲線救國。

CSS Code復(fù)制內(nèi)容到剪貼板
  1. textarea::-webkit-input-placeholder:after{   
  2.   display:block;   
  3.   content:"line@ \A line#";/*  \A 表示換行  */  
  4.   color:red;   
  5. };  

以上是webkit的代碼,F(xiàn)irefox類也有相應(yīng)的版本:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. textarea::-moz-placeholder:after{   
  2.   content:"line@ \A line#";/*  \A 表示換行  */  
  3.   color:red;   
  4. };     

相關(guān)文章

最新評論