Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input's caret height

I need help to change the caret's height - without changing the visual (hacks/tricks allowed as long as they work).
With that I mean I don't want to change the font's size (height and width), margins, paddings, color, background, border, etc, and if I do change it to achieve the caret's style, make it possible so I can put it back like a normal input, with it's styling capacities.

My best attempt was the following code:

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">

Ignore the text's selection weirdness if you need. I'm not caring about that for now.

If you have a way better solution, let me know. This is just some tests I have been doing, I don't exactly need the color to be red and the other attributes to be the way they are, but I do want it to still be possible to change them to whatherver I want.

Here's how it looks to me in case people don't get the same (using Chrome): enter image description here

like image 708
user7393973 Avatar asked Feb 08 '17 15:02

user7393973


People also ask

What is input caret?

A caret (sometimes called a "text cursor") is an indicator displayed on the screen to indicate where text input will be inserted. Most user interfaces represent the caret using a thin vertical line or a character-sized box that flashes, but this can vary. This point in the text is called the insertion point.

How do I make a caret in CSS?

C^ret is an online tool that helps you create a caret (or an arrow symbol) in pure CSS. The caret can be pointing in any direction, the border width, the color can be changed and the code is generated as you move the slider.

What is caret CSS?

The caret-color CSS property sets the color of the insertion caret, the visible marker where the next character typed will be inserted. This is sometimes referred to as the text input cursor. The caret appears in elements such as <input> or those with the contenteditable attribute.


1 Answers

It can be done, via "hacks".

Instead of an input box, you'd need a combination of javascript, css and span's...

source: codepen

source: blog

source: jsfiddle

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, .61, .355, 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>
like image 135
Unamata Sanatarai Avatar answered Sep 20 '22 07:09

Unamata Sanatarai