Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input cursor that is blinking

Tags:

html

css

forms

i am having trouble with making the input cursor to blink. How do you make an animation that the cursor "|" inside the input field (placeholder) keeps blinking. The code that i have is this:

<input type="text" class="rq-form-element" placeholder="|"/>

I have no idea on how to get this even started. Any suggestions?

like image 342
Tadej Bogataj Avatar asked Feb 27 '17 09:02

Tadej Bogataj


People also ask

What is the meaning of blinking cursor?

Alternatively referred to as a caret, a cursor or text cursor is a blinking horizontal or vertical line ( ) that indicates where new text starts when you begin to type.

Why is my mouse arrow blinking?

In applications such as Microsoft Word, the cursor changes to a vertical bar that blinks to indicate where you are in the document. But a cursor that flashes rapidly or flickers erratically may indicate problems with the mouse or mouse drivers, video problems or a cursor blink rate that is set too high.


2 Answers

Just add autofocus attribute. See the link here

<input type="text" class="rq-form-element" autofocus/>

The autofocus attribute is a boolean attribute. When present, it specifies that an element should automatically get focus when the page loads.

like image 124
Chaitali Avatar answered Sep 25 '22 02:09

Chaitali


Try this solution

<div class="cursor">
<input type="text" class="rq-form-element" />
<i></i>
</div>

CSS

.cursor {
    position: relative;
}
.cursor i {
    position: absolute;
    width: 1px;
    height: 80%;
    background-color: gray;
    left: 5px;
    top: 10%;
    animation-name: blink;
    animation-duration: 800ms;
    animation-iteration-count: infinite;
    opacity: 1;
}

.cursor input:focus + i {
    display: none;
}

@keyframes blink {
    from { opacity: 1; }
    to { opacity: 0; }
}

Live demo - https://jsfiddle.net/dygxxb7n/

like image 37
grinmax Avatar answered Sep 21 '22 02:09

grinmax