is there any CSS selector which is triggered after you type something in an input tag?

input type=text css
input html
input select css
textbox css style examples
input type select
css form styling examples
css selectors
css button selector

HTML:

<form method="post" action="#" autocomplete="off" id="validform">
                <div class="form-group col-sm-6">


                    <input type="text" class="form-control" id="name" required>
                    <span class="underline"></span>
                    <label for="name">Your name</label>

                </div>
                <div class="form-group col-sm-6">


                    <input type="email" class="form-control" id="email" required>
                    <span class="underline"></span>
                    <label for="email">Email</label>

CSS:

input:focus ~ label,
input:valid ~ label,
textarea:focus ~ label,
textarea:valid ~ label
{
    font-size: .8em;

    top: -20px;

    color: #24cf88;
}

So basically label shifts on top of an input tag whenever you focus on input tag or if it is valid . it works fine with text input , but with an email input it shifts back to the bottom unless you type the correct email format. How can i keep the text shifted to the top after i type something in an email input ?? i've included the link to the website if you'd like to check how it works.

https://baziiner21.github.io

Try to remove the type=email from the input and add your own validation with javascript

Learn About CSS Form: Using CSS Input Type With CSS Forms, CSS form styling creates a design for these elements. CSS attribute selectors select specific CSS input types for styling: input[type=text] - selects form fields that accept text. input[type=password] - selects form fields that accept input { width: 100px; /* When specifying this, you can use both px and % */ }. The [attribute~="value"] selector is used to select elements with an attribute value containing a specified word. The following example selects all elements with a title attribute that contains a space-separated list of words, one of which is "flower": [title~="flower"] { border: 5px solid yellow; Try it Yourself »

It's because you're using the :valid selector. You could always use the following:

input:invalid ~ label {
    font-size: .8em;
    top: -20px;
    color: #cf2424;
}

/* Extra for colouring the line based on invalid input */
input:invalid + span::after, input:invalid + span::before {
    background: #cf2424;
}

The above code would sit alongside your existing code

Change a text input's value with css?, ” when they are selected and ready to enter text (like when a cursor is blinking. There are three other types of selectors that use combinators: child selectors, adjacent sibling selectors, and general sibling selectors. When combined with one of the UI element states pseudo-classes, we can trigger events that would otherwise require jQuery, with simple CSS.

pattern="."

Just add that to your email field, it will change what is considered valid to by any character entered, then your valid/invalid css styling will work.

Edit: This will require you to use novalidate on your form to prevent the browser complaining about an invalid email format.

:focus, The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's "tab" key. When you create a new style in Dreamweaver using CSS features, you will need to choose which type of style you want to create and which ‘selector’ you want to use. Understanding (and remembering) the differences between the various types of style selectors can be a challenge.

:focus, Looks like a text input, but has validation parameters and relevant keyboard in its attributes; the type attribute, described with examples above, being the most important. A few additional non-standard attributes are listed following the There are CSS selectors that can specification target form controls  The most common child selector is the descendant selector, which matches every element that follows an identified ancestor. The descendant element does not have to come directly after the ancestor element inside the document tree, such as a parent-child relationship, but may fall anywhere within the ancestor element.

<input>: The Input (Form Input) element, Execute a JavaScript when a user writes something in an <input> field: <input type="text" oninput="myFunction()">. Try it Yourself ». More "Try it Yourself"  ID selectors are the most powerful type of selector in terms of CSS specificity. Meaning that they beat out other types of selectors and the styles defined within win. That sounds good, but that's typically considered bad, because it's nice to have lower-specificity selectors that are easier to override when needed.

oninput Event, HTML has the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element. To learn more about programming​  CSS Selectors In CSS, selectors are patterns used to select the element(s) you want to style. Use our CSS Selector Tester to demonstrate the different selectors.

Comments
  • Possible duplicate of Detect if an input has text in it using CSS -- on a page I am visiting and do not control?
  • Did you find the answer you were looking for?
  • Rather than removing the type=email, I'd use JavaScript to detect if the input is filled instead to keep the semantics intact. I'd also use JavaScript validation anyway as the browsers don't all get it right.