2015-10-19 71 views
1

當我打開模式窗口時,textarea中的onfocus文本值以藍色突出顯示。我不確定應該使用什麼CSS屬性從文本中刪除突出顯示的onfocus藍色。我嘗試了下面,但它不起作用。刪除焦點上的藍色突出顯示的文本

input[type="text"], textarea{ 
    outline: none; 
    box-shadow:none !important; 
    border:1px solid #ccc !important; 
} 

Text filed value highlighted in blue

+0

嘗試了這一點':重點{大綱:無;}'http://stackoverflow.com/questions/2943548/best-way-to-reset-remove-chromes-input -highlighting對焦邊界 – FBHY

回答

0

您可以使用user-select避免任何文本的選擇

input { 
 
    -webkit-user-select: none; /* Chrome all/Safari all */ 
 
    -moz-user-select: none;  /* Firefox all */ 
 
    -ms-user-select: none;  /* IE 10+ */ 
 
    user-select: none;   /* Likely future */  
 
}
<input type="text">

要小心,因爲你避免選擇提示用戶,並導致可訪問性丟失。

0

user-select屬性suggested by Marcos一種替代方法是使用::selection::-moz-selection上自己的規則)以特異性設置/取消的顏色/所選文本的背景(無需禁用選擇功能)。

input[type="text"]::selection, 
 
textarea::selection { 
 
    background-color: inherit; 
 
    color: red; 
 
} 
 
input[type="text"]::-moz-selection, 
 
textarea::-moz-selection { 
 
    background-color: inherit; 
 
    color: red; 
 
} 
 

 
input[type="text"], 
 
textarea { 
 
    outline: none; 
 
    box-shadow: none !important; 
 
    border: 1px solid #ccc !important; 
 
}
<input type="text" value="test value for selection" /> 
 
<hr/> 
 
<textarea>test text for selection</textarea>

相關問題