After I click the 'submit' or 'reset' button, the button color stays the hover color and does not return to the original "pre-clicked" button color until you click elsewhere in the page.
I essentially want the button color to change back to the original color after it is clicked. Can anyone suggest how to do this?
CSS/HTML:
.form input:focus {
background: #FFFFAD;
outline: none;
}
.buttons {
text-align: left;
}
.buttons input {
font-size: 2.5em;
font-weight: bold;
font-family: "Arial", serif;
padding: 8px 40px;
background: #4470B6;
border: 0px;
margin-left: 0px;
margin-right: 50px;
margin-top: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
box-shadow: 0 0 4px rgba(0, 0, 0, .75);
color: #FFFAFA;
}
.buttons input:hover,
.buttons input:focus {
background-color: #50627E;
outline: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
box-shadow: 0 0 1px rgba(0, 0, 0, .75);
}
<!-- Details Form -->
<section class="details">
<form id="form" action="test.php" method="post" autocomplete="on" target="_blank">
<div class="form">
<label>First Name:</label>
<input type="text" name="firstname" placeholder="First Name" autofocus />
</div>
<div class="buttons">
<input type="submit" value="Search">
<input type="reset" value="Reset">
</div>
</form>
</section>
i assume you are styling your button on focus in order to get rid of the outline, so simply split the selector into 2 and on focus remove only the outline:
.form input:focus {
background: #FFFFAD;
outline: none;
}
.buttons {
text-align: left;
}
.buttons input {
font-size: 2.5em;
font-weight: bold;
font-family: "Arial", serif;
padding: 8px 40px;
background: #4470B6;
border: 0px;
margin-left: 0px;
margin-right: 50px;
margin-top: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
box-shadow: 0 0 4px rgba(0, 0, 0, .75);
color: #FFFAFA;
}
.buttons input:hover
{
background-color: #50627E;
outline: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
box-shadow: 0 0 1px rgba(0, 0, 0, .75);
}
.buttons input:focus {
outline: none;
}
<!-- Details Form -->
<section class="details">
<form id="form" action="test.php" method="post" autocomplete="on" target="_blank">
<div class="form">
<label>First Name:</label>
<input type="text" name="firstname" placeholder="First Name" autofocus />
</div>
<div class="buttons">
<input type="submit" value="Search">
<input type="reset" value="Reset">
</div>
</form>
</section>
You are very close to the solution. In order to achieve the effect you are looking for try using focus and active instead of hover and focus.
The active state is only triggered when the element is being clicked.
Here is what I did
.buttons input:focus {
outline: none
}
.buttons input:active {
border: 0;
background-color: #50627E;
outline: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
box-shadow: 0 0 1px rgba(0, 0, 0, .75);
}
You can check the full solution bellow:
.form input:focus {
background: #FFFFAD;
outline: none;
}
.buttons {
text-align: left;
}
.buttons input {
font-size: 2.5em;
font-weight: bold;
font-family: "Arial", serif;
padding: 8px 40px;
background: #4470B6;
border: 0px;
margin-left: 0px;
margin-right: 50px;
margin-top: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
box-shadow: 0 0 4px rgba(0, 0, 0, .75);
color: #FFFAFA;
}
.buttons input:focus {
outline: none
}
.buttons input:active {
border: 0;
background-color: #50627E;
outline: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
box-shadow: 0 0 1px rgba(0, 0, 0, .75);
}
<!-- Details Form -->
<section class="details">
<form id="form" action="test.php" method="post" autocomplete="on" target="_blank">
<div class="form">
<label>First Name:</label>
<input type="text" name="firstname" placeholder="First Name" autofocus />
</div>
<div class="buttons">
<input type="submit" value="Search">
<input type="reset" value="Reset">
</div>
</form>
</section>
As i had same issue BUT on mobile. Mobile has thing called sticky hover. ended up # media(hover: hover) styles.
REFERENCED TEXT:
You could for example, define your normal :hover styles inside the media query (#media hover:hover{}) to restrict them to devices that support :hover fully (ones equip with a mouse or certain pointing devices):
#media (hover:hover) {
nav a:hover{
background: yellow;
}
}
or for a more progressive approach that leaves your original :hover styles untouched, target devices that don't support :hover completely:
#media (hover:none), (hover:on-demand) {
nav a:hover{ /* suppress hover effect on devices that don't support hover fully
background: none;
}
}
Reference: http://javascriptkit.com/dhtmltutors/sticky-hover-issue-solutions.shtml
and this: How to prevent sticky hover effects for buttons on touch devices
that's because :hover and :focus background color are same
So i added background color for :hover only and no background color for :focus
if you wish you can just remove this class form css .buttons input:focus
.form input:focus {
background: #FFFFAD;
outline: none;
}
.buttons {
text-align: left;
}
.buttons input {
font-size: 2.5em;
font-weight: bold;
font-family: "Arial", serif;
padding: 8px 40px;
background: #4470B6;
border: 0px;
margin-left: 0px;
margin-right: 50px;
margin-top: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, .75);
box-shadow: 0 0 4px rgba(0, 0, 0, .75);
color: #FFFAFA;
}
.buttons input:hover,
.buttons input:focus {
outline: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, .75);
box-shadow: 0 0 1px rgba(0, 0, 0, .75);
}
.buttons input:hover{
background-color: #50627E;}
<!-- Details Form -->
<section class="details">
<form id="form" action="test.php" method="post" autocomplete="on" target="_blank">
<div class="form">
<label>First Name:</label>
<input type="text" name="firstname" placeholder="First Name" autofocus />
</div>
<div class="buttons">
<input type="submit" value="Search">
<input type="reset" value="Reset">
</div>
</form>
</section>
Related
I got a custom HTML-object and every way I tried to center the class, it failed. Does anybody have an idea? Kind regards.
I tried . Other objects ere centered, only this one wasn't. I tried margin: 0px auto. I tried . My custom object keeps left-aligned. I think there could be an attribute
.switch-mode {
display: flex;
margin-bottom: 36px;
overflow: hidden;
}
.switch-mode input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-mode label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 16px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}
.switch-mode label:hover {
cursor: pointer;
}
.switch-mode input:checked+label {
background-color: #C23434;
box-shadow: none;
}
.switch-mode label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-mode label:last-of-type {
border-radius: 0 4px 4px 0;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switch-mode">
<input type="radio" id="radio-open" name="mode" />
<label for="radio-open">OPEN</label>
<input type="radio" id="radio-auto" name="mode" />
<label for="radio-auto">AUTO</label>
<input type="radio" id="radio-close" name="mode" />
<label for="radio-close">CLOSE</label>
</div>
</body>
</html>
Your container is what needs to be centered, not the items within it. The addition is justify-content: center; within the .switch-mode class.
.switch-mode {
display: flex;
margin-bottom: 36px;
overflow: hidden;
justify-content: center;
}
.switch-mode input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-mode label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 16px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}
.switch-mode label:hover {
cursor: pointer;
}
.switch-mode input:checked+label {
background-color: #C23434;
box-shadow: none;
}
.switch-mode label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-mode label:last-of-type {
border-radius: 0 4px 4px 0;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switch-mode">
<input type="radio" id="radio-open" name="mode" />
<label for="radio-open">OPEN</label>
<input type="radio" id="radio-auto" name="mode" />
<label for="radio-auto">AUTO</label>
<input type="radio" id="radio-close" name="mode" />
<label for="radio-close">CLOSE</label>
</div>
</body>
</html>
On .switch-mode, you have used flex layout. So add justify-content: center on .switch-mode class and it will be aligned on center position.
.switch-mode {
display: flex;
margin-bottom: 36px;
overflow: hidden;
justify-content: center;
}
.switch-mode input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-mode label {
background-color: #e4e4e4;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
line-height: 1;
text-align: center;
padding: 8px 16px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}
.switch-mode label:hover {
cursor: pointer;
}
.switch-mode input:checked+label {
background-color: #C23434;
box-shadow: none;
}
.switch-mode label:first-of-type {
border-radius: 4px 0 0 4px;
}
.switch-mode label:last-of-type {
border-radius: 0 4px 4px 0;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switch-mode">
<input type="radio" id="radio-open" name="mode" />
<label for="radio-open">OPEN</label>
<input type="radio" id="radio-auto" name="mode" />
<label for="radio-auto">AUTO</label>
<input type="radio" id="radio-close" name="mode" />
<label for="radio-close">CLOSE</label>
</div>
</body>
</html>
I'm having difficulty with the following code - everything works as I wish it EXCEPT the contents of the check boxes. The ticks and crosses are too low.
Can someone tell me what I am doing wrong here please? I admit I hacked this code from several sources and glued it together, so I'm more than happy to admit I have misunderstood something or other.
Thanks!
.checkbox {
display: inline-block;
float: left;
width: 25%;
font-size: 16px;
line-height: 36px;
text-align: left;
}
input[type=checkbox] {
display: none;
}
.checkbox:before {
display: inline-block;
width: 18px;
height: 18px;
content: "\2715\0020";
background-color: #f3f3f3;
color: #000000;
text-align: center;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 3px;
margin: 0px 10px 0px 0px;
vertical-align: middle;
}
input[type=checkbox]:checked+.checkbox:before {
color: #f3f3f3;
background-color: #abcdef;
content: "\2714\0020";
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
}
<section>
<form>
<input id="option1" type="checkbox">
<label class="checkbox" for="option1">Unchecked</label>
<input id="option2" type="checkbox" checked>
<label class="checkbox" for="option2">Checked, changeable</label>
<input id="option3" type="checkbox" checked disabled>
<label class="checkbox" for="option3">Checked, fixed</label>
<input id="option4" type="checkbox" checked disabled>
<label class="checkbox" for="option4">Checked, fixed</label>
<input id="option5" type="checkbox">
<label class="checkbox" for="option5">Unchecked</label>
</form>
</section>
Add line-height to .checkbox:before{...} set it to 20px, or play this number,
.checkbox:before {
display: inline-block;
width: 18px;
height: 18px;
content: "\2715\0020";
background-color: #f3f3f3;
color: #000000;
text-align: center;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 3px;
margin: 0px 10px 0px 0px;
vertical-align: middle;
line-height: 20px;
}
Add line-height: 1.2; to your .checkbox:before:
.checkbox:before {
display: inline-block;
width: 18px;
height: 18px;
content: "\2715\0020";
background-color: #f3f3f3;
color: #000000;
text-align: center;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 3px;
margin: 0px 10px 0px 0px;
vertical-align: middle;
line-height: 1.2; /* add this*/
}
.checkbox {
display: inline-block;
float: left;
width: 25%;
font-size: 16px;
line-height: 36px;
text-align: left;
}
input[type=checkbox] {
display: none;
}
.checkbox:before {
display: inline;
padding:2px;
width: 18px;
height: 18px;
content: "\2715\0020";
background-color: #f3f3f3;
color: #000000;
text-align: center;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 3px;
margin: 0px 10px 0px 0px;
vertical-align: middle;
}
input[type=checkbox]:checked+.checkbox:before {
color: #f3f3f3;
background-color: #abcdef;
content: "\2714\0020";
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
}
<section>
<form>
<input id="option1" type="checkbox">
<label class="checkbox" for="option1">Unchecked</label>
<input id="option2" type="checkbox" checked>
<label class="checkbox" for="option2">Checked, changeable</label>
<input id="option3" type="checkbox" checked disabled>
<label class="checkbox" for="option3">Checked, fixed</label>
<input id="option4" type="checkbox" checked disabled>
<label class="checkbox" for="option4">Checked, fixed</label>
<input id="option5" type="checkbox">
<label class="checkbox" for="option5">Unchecked</label>
</form>
</section>
I having problems trying to get a log and a search box to go side by side. The logo on the left and the search box on the right.
header {
background:#383838;
height: 130px;
border-top:10px solid #2C2C2C; border-bottom:1px solid #2C2C2C;
}
.wrap-header {
width:960px;
position:relative;
margin: 0px auto;
}
header #logo {
position:absolute;
top:40px;
left: 30px;
width: 100%;
}
header #search,
header #submit {
position: absolute;
top: 60px;
right: 20px;
width: 258px;
z-index: 15;
}
header #search {
padding: 5px 9px;
height: 20px;
width: 300px;
border: 1px solid #a4c3ca;
background: #f1f1f1;
border-radius: 50px 3px 3px 50px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
}
header #submit
{
background-color: #6cbb6b;
background-image: linear-gradient(#95d788, #6cbb6b);
border-radius: 3px 50px 50px 3px;
border-width: 1px;
border-style: solid;
border-color: #7eba7c #578e57 #447d43;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3),
0 1px 0 rgba(255, 255, 255, 0.3) inset;
height: 35px;
margin: 0 0 0 10px;
padding: 0;
width: 90px;
cursor: pointer;
font: bold 14px Arial, Helvetica;
color: #23441e;
text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}
header #submit:hover {
background-color: #95d788;
background-image: linear-gradient(#6cbb6b, #95d788);
}
header #submit:active {
background: #95d788;
outline: none;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
}
header #submit::-moz-focus-inner {
border: 0; /* Small centering fix for Firefox */
}
header #search::-webkit-input-placeholder {
color: #9c9c9c;
font-style: italic;
}
<header>
<div class="wrap-header">
<div id="logo"><img src="./images/logo.png"/></div>
<form id="searchbox" action="search.php" method="post">
<input id="search" type="text" placeholder="Type here" name="search">
<input name="submit" type="submit" id="submit" formmethod="POST" value="Search">
</form>
</div>
</header>
What is happening is the logo is okay but the submit button for the search-box is inside the text-box for the search.
Just edit following css header #search class
header #search {
padding: 5px 9px;
height: 20px;
margin-right: 90px;
width: 300px;
border: 1px solid #a4c3ca;
background: #f1f1f1;
border-radius: 50px 3px 3px 50px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);
}
It will do the job well.. Here is the preview
Edit
You need toadd min-width to your header element
Here's working jsfiddle http://jsfiddle.net/otbay822/
<header>
<div class="wrap-header">
<div id="logo" class="inline-div">
<img src="./images/logo.png"/>
</div>
<div class="inline-div">
<form id="searchbox" action="search.php" method="post">
<input id="search" type="text" placeholder="Type here" name="search">
<input name="submit" type="submit" id="submit" formmethod="POST" value="Search">
</form>
</div>
</div>
</header>
CSS:
.inline-div{
display:inline-block;
}
I Wrapped the Form in a div and applied a class too both the form and the logo div. And then simply applied display:inline-block;
Hope it Helps.
I am trying to get a form styled with css on my webpage, but i cant seem to get the form to recognize the css.As you can see below I am simply trying to stlye the element below is the code. Any thoughts? I am sure the solution is cake, new programmer over here.. any and all help is appreciated!
CSS
form {
background: -webkit-gradient(linear, bottom, left 175px, from(#CCCCCC), to(#EEEEEE));
background: -moz-linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
margin: auto;
position: relative;
width: 550px;
height: 450px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-style: italic;
line-height: 24px;
font-weight: bold;
color: #09C;
text-decoration: none;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
padding: 10px;
border: 1px solid #999;
border: inset 1px solid #333;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
}
input {
width: 375px;
display: block;
border: 1px solid #999;
height: 25px;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
}
textarea#feedback {
width: 375px;
height: 150px;
}
textarea.message {
display: block;
}
input.button {
width: 100px;
position: absolute;
right: 20px;
bottom: 20px;
background: #09C;
color: #fff;
font-family: Tahoma, Geneva, sans-serif;
height: 30px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 1p solid #999;
}
input.button:hover {
background: #fff;
color: #09C;
}
textarea:focus, input:focus {
border: 1px solid #09C;
}
HTML
<form>
<div>
<h1>Contact Form :</h1>
<label>
<span>Your name</span><input id="name" type="text" name="name" />
</label>
<label>
<span>Email Address</span><input id="email" type="text" name="email" />
</label>
<label>
<span>Subject</span><input id="subject" type="text" name="subject" />
</label>
<label>
<span>Message</span><textarea id="feedback" name="feedback"></textarea>
<input type="button" value="Submit Form" />
</label>
</div>
</form>
I want to create a page like in image
Problem:
Main box Shadow not coming as in image.
I have tried with my own HTMl and CSS code.
Here is fiddle
http://jsfiddle.net/EE6hU/
HTML
<div class='wrapper' id='id_wrapper'>
<div class='main'> <span class='online_survey'>Online Survey</span>
<div class='login_box'>
<div class='login'>
<form>
<div class='label'>username</div>
<input type='text' name='username' class='loginInput' placeholder='moderator' />
<div style='clear:both'></div>
<div class='label'>password</div>
<input type='password' name='password' class='loginInput' placeholder='*********' />
<div style="clear:both"></div>
<input type='checkbox' name='remember' class='check' />
<div class='remember'>Remember me</div>
<input type='submit' name='submit' class='submit_button' value='submit' />
</form>
</div>
<div class='forget_pass'><a href='#'>Forget Password</a>
</div>
</div>
</div>
</div>
CSS
.wrapper {
background:#313131;
height:645px;
}
.main {
margin: 0 auto;
position: relative;
top: 20%;
width: 500px;
}
.online_survey {
bottom: 10px;
color: #FFFFFF;
font-size: 20px;
margin-left: 15px;
position: relative;
}
.user_name {
}
.login_box {
background: none repeat scroll 0 0 #7D7D7D;
border: 1px solid #98B2C9;
border-radius: 20px;
padding: 8px;
box-shadow: 0px 0px 10px 4px rgba(69, 68, 68, 0.75);
-moz-box-shadow: 0px 0px 10px 4px rgba(69, 68, 68, 0.75);
-webkit-box-shadow: 0px 0px 10px 4px rgba(69, 68, 68, 0.75);
}
.loginInput {
background:#313131;
border-radius: 5px;
float: left;
height: 30px;
width: 200px;
margin: 5px;
padding:5px;
color:#ffffff;
}
.label {
float: left;
height: 30px;
width: 140px;
}
.login {
padding: 30px;
}
.forget_pass a {
color: white;
text-decoration:none;
}
.submit_button {
}
.check {
float: left;
margin-left: 140px;
margin-right: 5px;
}
ge.
Stacking shadows of various sizes might get you close.
http://jsfiddle.net/isherwood/EE6hU/1
.login_box {
box-shadow: 0px 0px 10px 4px rgba(69, 68, 68, 0.75),
0 0 150px rgba(255,255,255,0.5),
0 0 250px rgba(255,255,255,0.5);
}
I may have to eat my own words. Here's a way to get the narrower white shadow in your image:
http://jsfiddle.net/isherwood/EE6hU/4
.login_box {
...
box-shadow: 0px 0px 10px 4px rgba(69, 68, 68, 0.75);
margin: 0 -150px;
}
.login_box_shadow {
overflow: visible;
border-radius: 20px;
box-shadow: 0 0 150px rgba(255, 255, 255, 0.5),
0 0 250px rgba(255, 255, 255, 0.5);
margin: 0 150px;
}