There is a css selector that I can select an Submit input only when it is triggered/clicked

Asked

Viewed 599 times

2

my doubt is as follows:

Is there any way to select only with css a tag <input type="submit">only when it is clicked/triggered.

2 answers

5

When you click on the input, it gets the status of :focus:

input[type=submit]:focus {
  color: red;
}

Editing: as reported in Hugo’s reply, :active occurs when button is clicked. The :focus may occur when the button is clicked, via TAB key or via script.

When the focus is removed it returns to its original state.

Example:

input[type=submit]:focus {
  color: red;
}
<input type="submit">

  • 1

    That’s still an option depending on the case

  • Thanks! Really. :D

4


I think I understood the question differently, I believe he wants to "shoot" some property in the click. And in that case would be with the :active

inserir a descrição da imagem aqui

Follows code referring to image above:

[type="submit"]:active {
    box-shadow: none;
    transition: box-shadow 100ms;
}
[type="submit"]:active {
    box-shadow: 0 0 20px red;
}
<input type="submit" value="Clique aqui">


OBS

Any element can receive a :active

The :active pseudo-class is also typically Matched when using the Keyboard tab key. It is Frequently used on <a> and <button> HTML Elements, but may not be Limited to just those.

PORTUGUÊS "The pseudo-class :active is also commonly used when using the keyboard tab key. It is often used in HTML elements <a> and <button>, but may not be limited only to them."

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/:active

  • I really believe :active is the purpose of the question. : D

  • @Sam boy leaves his answer tbm Uai, even for the sake of seo, Pq sometimes people google but do not know the terms being, and Focus may be better for them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.