1

change text input border color on hit by css

Hello

I've this html field

<input type=text value=test id=ff>

I am using this css code to set a border

#ff{
border:1px #000 solid
}

I want to change the border color to ( red ), when I click on the field

For example: The google search field, when you hit the search field to write anything, the border will change to blue

1 Answer 1

5
#ff:focus {border-color: #f00; }

For IE7 you can use JavaScript (jQuery in particular), for example:

<style>
    #ff:focus,
    #ff.focus {border-color: #f00; }
</style>

<!--[if lte IE 7]>
<script>
$('#ff').focus(function() {
    $(this).addClass('focus');
}).blur(function() {
    $(this).removeClass('focus');
});
</script>
<![endif]-->
Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much, it's works fine.. but why it does not work with IE 7?? How i can use it with IE7?
IE7 is too old browser and just does not support :focus pseudoclass. You can use JavaScript if needed. But given that it is not a critical functionality, it's perfectly OK to not care about IE7 in this case.

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.