【问题标题】:can I add <span> inside <textarea> and make it useful?我可以在 <textarea> 中添加 <span> 并使其有用吗?
【发布时间】:2017-01-17 03:57:54
【问题描述】:
<!DOCTYPE html>
<html>
<head>
    <style>
        span {
            color: red;
        }
    </style>
</head>
<body>

        <textarea readonly cols=200 rows=40>
            <span>
                hahahahaha
            </span>
        </textarea>

</body>
</html>

在这个例子中,有没有办法让&lt;span&gt;中的文字变成红色 还是可以通过&lt;textarea&gt;等其他html标签来完成?

【问题讨论】:

标签: css html tags


【解决方案1】:

不,您不能将 HTML 元素放在表单字段标记内,例如 textareainput。但是,您可以使用普通 CSS 将 textarea 中的颜色设为红色。

textarea {
  color: red;
}
&lt;textarea&gt;text&lt;/textarea&gt;

【讨论】:

    【解决方案2】:

    您还可以使用另一种方法是调整占位符属性的样式。

    链接到jsfiddle

    希望这会有所帮助。

    ::-webkit-input-placeholder {
       color: red;
    }
    
    :-moz-placeholder { /* Firefox 18- */
       color: red;  
    }
    
    ::-moz-placeholder {  /* Firefox 19+ */
       color: red;  
    }
    
    :-ms-input-placeholder {  
       color: red;  
    }
    Who are you?<br />
    <textarea readonly rows="4" cols="50" placeholder="Describe yourself here..."></textarea><br />
    <input type="text" placeholder="red" />

    【讨论】:

      【解决方案3】:

      好的,现在我知道我无法插入

      我还有别的办法

      <style type="text/css"> 
              .testDiv{ 
                  bottom: 36px;
                  height: calc(100vh - 280px);
                  resize: none;
                  overFlow-x:scroll; 
                  overFlow-y:scroll; 
              } 
              .keyword{
                  color:red;
              }
      </style> 
      
      <div class='testDiv' id="keyword">
                  one<br>
                  two<br>
                  three<br>
                  <span class="keyword">four</span><br>
      </div>
      

      只需在 div 中添加滚动、高度 css

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-23
        • 1970-01-01
        • 2021-04-18
        • 2022-01-06
        • 2011-06-28
        • 1970-01-01
        • 2014-02-27
        相关资源
        最近更新 更多