我需要帮助才能改变插入符号的高度,而不会改变视觉(只要工作时允许使用黑客/技巧).这就意味着我不想更改字体的大小(高度和宽度),边距,颜色,背景,边框等,如果我改变它来实现插入符号的风格,可以让我可以把它像普通的输入一样,具有它的造型能力.
我最好的尝试是以下代码:
body{ background-color: lightBlue; } #background{ color: red; height: 61px; margin-top: 0px; text-shadow: 0 0 0 transparent; width: 173px; -webkit-text-fill-color: transparent; -webkit-transform: scale(1,calc(1/3)); } #text{ background-color: transparent; border-color: transparent; color: red; left: 8px; pointer-events: none; position: absolute; top: 103px; }
<span>Caret's height (pixels):</span> <br> <br> <input placeholder="15 (default)" spellcheck="false"> <br> <br> <input id="background" oninput="document.getElementById('text').value=this.value" spellcheck="false"> <input id="text" placeholder="5 (1/3)" onfocus="this.blur()" spellcheck="false" tabindex="-1">
如果需要,请忽略文本的选择异常.我现在不在乎.
如果你有一个更好的解决方案,让我知道.这只是我一直在做的一些测试,我不完全需要颜色为红色,其他属性是他们的方式,但我仍然希望将其更改为我想要的.
解决方法
可以通过“黑客”来完成.
而不是输入框,您需要使用javascript,css和span的组合
document.documentElement.setAttribute("class","js"); var searchFauxInput = document.querySelector(".fb-Search_FauxInput"); var searchBox = document.getElementById("Input"); searchBox.addEventListener("keyup",function copyInput(event) { searchFauxInput.textContent = searchBox.value; searchBox.setAttribute("value",searchBox.value); },false);
* { Box-sizing: border-Box; } body { background-color: #555; font-family: sans-serif; } .fb-Search { display: -webkit-Box; display: -ms-flexBox; display: flex; height: 44px; padding: 5px 70px 5px 5px; width: 400px; position: relative; background-color: #e4e4e4; } .fb-Search_Input { -webkit-appearance: none; -moz-appearance: none; appearance: none; } .js .fb-Search_Input { position: absolute; left: -100vw; } .fb-Search_FauxInput { display: none; -webkit-Box-align: center; -ms-flex-align: center; align-items: center; max-width: 80%; margin-top: 14px; border: 0; font-size: 20px; font-size: 1.3rem; color: #777; background-color: #e4e4e4; border-right: 3px solid transparent; height: 3px; } .js .fb-Search_FauxInput { display: -webkit-Box; display: -ms-flexBox; display: flex; } .fb-Search_Input:focus ~ .fb-Search_FauxInput { -webkit-animation: pulseAttention 1.5s cubic-bezier(.215,.61,.355,1) forwards infinite; animation: pulseAttention 1.5s cubic-bezier(.215,1) forwards infinite; } .fb-Search_Label { position: absolute; top: 0; right: 0; bottom: 0; left: 0; padding: 5px; display: -webkit-Box; display: -ms-flexBox; display: flex; -webkit-Box-align: center; -ms-flex-align: center; align-items: center; color: #a7a7a7; font-size: 15px; } .fb-Search_Input:not([value=""]) ~ .fb-Search_Label { -webkit-Box-pack: end; -ms-flex-pack: end; justify-content: flex-end; } @-webkit-keyframes pulseAttention { 50% { border-color: green; } } @keyframes pulseAttention { 50% { border-color: green; } }
<div class="fb-Search"> <input id="Input" class="fb-Search_Input" value=""> <span class="fb-Search_FauxInput" dir="rtl"></span> <label class="fb-Search_Label" for="Input">Search</label> </div>