Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  157] [ 1]  / answers: 1 / hits: 18496  / 13 Years ago, sun, october 9, 2011, 12:00:00

I am making a website and would like the border color of the text boxes to change on hover and when they are clicked.



I have searched and found a few people showing the code for how to do it. I tried to run it from my LAMP server (dont know if embedded JS will work on a Lamp server) although it didnt work. The code was javascript which I don't really know so I couldn't understand what what was going wrong.



This is the code:



onload=function(){
var inp=document.getElementsByTagName('input'), i=0, t ;
while(t==inp[i++]){
if(t.type=='text'){
t.onclick=function(){this.style.border='1px solid red'}
}
}
}

</script>


Is there a way to do what I am wanting just with CSS/html or will I need to learn JavaScript as well?



If its not too hard could explain how to do it or show me some example code?



Cheers - Cohen.


More From » html

 Answers
6

Yes this can be done using CSS pseudo-classes



Here is an example:



<style>
.fancyText:hover{border:1px solid red;}
.fancyText:focus{border:1px solid red;}
</style>
<input type='text' class='fancyText' />

[#89718] Friday, October 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;