1

The following HTML markup

<div id="child">
    <input type="text"/>
</div>

and CSS stylesheet

input[type="text"]:focus{
    border: 1px solid green;
}
#child {
    border: 10px solid grey;
    border: 20px black solid;
    background: aqua;
    height: 50px;
    margin: 10px;
}

are given. But I want the effect of applying both hover and focus pseudo-classes. I think that copy-paste of code like this:

input[type="text"]:focus{
    border: 1px solid green;
}

input[type="text"]:hover{
    border: 1px solid green;
}

isn’t a best way, because it's very upsize code. Is there a way to do it without applying JS?

2
  • 2
    You mean like.. input[type="text"]:hover, input[type="text"]:focus {} ? Commented Dec 22, 2013 at 23:58
  • :focus and :hover are pseudo-classes, not pseudo-elements (I edited it in your question). Commented Dec 23, 2013 at 5:18

1 Answer 1

2

Something that helps to reduce your code by having a single style block for multiple selectos, in your case:

input[type="text"]:focus, input[type="text"]:hover
{
    border: 1px solid green;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.