INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

input:hover[type="submit"]

input:hover[type="submit"]

(OP)
Hi everyone,
This is my code:

CODE

<!DOCTYPE html>
<html lang = "en">
<head>
	<title>test</title>
	<style>
		input:hover[type="submit"] 
		{
			background: red;
		}
		
	</style>
</head>
<body>
	<form method = "GET" action = "test.php" >
		<label for = "fromDAte" >xxx</label>
		<input type = "date" name = "fromDate" >
		<input type="submit"  name = "myInput">									
	</form>
</body>
</html> 
When I run it I get screenshot no. 1 as displayed at the attached image. When I "submit" is hovered I get screenshot
no. 2, "submit" in red, exactly like required by the code above.
When I add "submit" a style the "submit" input tag looks like this:

CODE

<input type="submit"  name = "myInput" style = "background-color: blue"> 
the whole code looks like this:

CODE

<!DOCTYPE html>
<html lang = "en">
<head>
	<title>test</title>
	<style>
		input:hover[type="submit"] 
		{
			background: red;
		}
		
	</style>
</head>
<body>
	<form method = "GET" action = "test.php" >
		<label for = "fromDAte" >xxx</label>
		<input type = "date" name = "fromDate" >
		<input type="submit"  name = "myInput" style = "background-color: blue">									
	</form>
</body>
</html> 
And the new display look like "3" at the attached image.
But !!!!!!!
When I hover over "submit" color remains blue and is not changed to red despite the internal style sheet that
works fine until "background-color" style is added at inline style.
My question is:
Why does "input:hover[type="submit"]" not work after I add inline style "background-color"?
Thanks

RE: input:hover[type="submit"]

Hi

I would say, it is CSS specificity issue. Avoid using inline style.

Feherke.
feherke.github.io

RE: input:hover[type="submit"]

Because the inline style overrides the styles in the head.

Basically the inline style is more specific than the style above which means its the one that gets applied to the element. And since the inline style has no state defintition, it applies to all states of the element, including "hover".

A bit about CSS style specificity:
https://www.smashingmagazine.com/2007/07/css-speci...

If you want to keep the hover, don't add an inline style that overrides the same attribute.

Add the style to the head hcss. If you need to apply a different color to a different input use classes.


CODE

!DOCTYPE html>
<html lang = "en">
<head>
	<title>test</title>
	<style>
		input[type="submit"].bluebtn 
		{
			background-color:blue;
		}
		
		input[type="submit"].greenbtn 
		{
			background-color:green;
		}
		
		input:hover[type="submit"] 
		{
			background: red;
		}
		
	</style>
</head>
<body>
	<form method = "GET" action = "test.php" >
		<label for = "fromDAte" >xxx</label>
		<input type = "date" name = "fromDate" >
		<input type="submit"  name = "myInput" class="bluebtn">
		<input type="submit"  name = "myInput" class="greenbtn">											
	</form>
</body>
</html> 

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: input:hover[type="submit"]

(OP)
Thanks a lot Vacunita. This was very helpful !

RE: input:hover[type="submit"]

(OP)
Thanks feherke !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close