CSS: Hover a HTML submit button - html

I'm trying to style a HTML submit button in CSS:
HTML:
<input type="submit" value="Yes" id="popUpYes">
CSS:
#popUpYes
{
width: 60px;
height: 30px;
background-color: black;
}
#popUpYes:hover
{
background-color: white;
}
The basic style works but the background does not change color on hover.

Your original code works for me. Be sure you don't have any other conflicting styles inherited by the submit button.

Try this JSfiddle
Try this:
#popUpYes {
width: 60px;
height: 30px;
background-color: black;
color: white;
/* SET COLOR IN WHITE */
}
#popUpYes:hover {
background-color: white;
color: black;
/* SET COLOR IN BLACK */
}
<input type="submit" value="Yes" id="popUpYes">
You have to assign the color - attribute for the text.

I tried this in Chrome and it worked.
#popUpYes {
width: 60px;
height: 30px;
background-color: black;
color: #fff;
}
#popUpYes:hover {
background-color: white;
}
<input type="submit" value="Yes" id="popUpYes">

As per your question "The basic style works but the background does not change color on hover." , this happens only when you set your BackColor or background-color through properties. your code works fine because you have used css class instead of properties.

The code as it is now working -> http://jsfiddle.net/2wYqd/ What is your browser?
#popUpYes {
width: 60px;
height: 30px;
background-color: black;
}
#popUpYes:hover {
background-color: white;
}

My work may be of use to you in this regard.
input[type=submit] {
background-color: #42b72a;
color: white;
border: 5px solid #42b72a;
width: 200px;
}
#kayitol:hover {
box-shadow: 0 0 10px #0099ff;
font-weight: bold;
color: black;
}
input[type=reset] {
background-color: #FF8A80;
color: white;
border: 5px solid #FF8A80;
width: 120px;
}
#iptal:hover {
box-shadow: 0 0 10px #FF3C41;
font-weight: bold;
color: black;
}
<input type="submit" id="kayitol" value="Kayıt Ol">
<input type="reset" id="iptal" value="Vaz Geçtim">

Working fine link
#popUpYes {
width: 60px;
height: 30px;
background-color: black;
color:white;
}
#popUpYes:hover {
background-color: white;
color: black;
}

Related

CSS button does not highlight properly

I have this button which doesn't highlight properly when I click on it, please see the image, and CSS file down below
CSS for the toggle button:
.mat-button-toggle {
box-sizing: border-box;
height: 33px;
width: 159px;
border: 1px solid #E1E1E1;
border-radius: 2px;
background-color: #FFFFFF;
}
.mat-button-toggle:hover {
border: 1px #000 solid !important;
background-color: #FFF !important;
border-radius: 5px !important;
}
CSS for the text
.ticket {
margin-top: 5px;;
height: 18px;
width: 122px;
color: #111111;
font-family: Arial;
font-size: 16px;
letter-spacing: 0;
line-height: 18px;
}
HTML
<mat-button-toggle-group name="fontStyle" aria-label="Font Style" >
<mat-button-toggle routerLink="ticketView" value="ticketView">
<div class="ticket" id="p1">
{{'TicketOverView' | translate}}
</div>
</mat-button-toggle>
My guess is there is something else in your css html going on. I have recreated your css in codepen for you and couldn't reproduce your results.
I would double check your html markup.
Here is the codepen I produced
https://codepen.io/jmllr89/pen/KKdzLGw
Also you do not need !important on the :hover pseudo-class. CSS is smart enough to recognize what needs to be changed. So simply define your initial state in mat-button-toggle and then in mat-button-toggle:hover you create a second state, and css will make the necessary changes.
.mat-button-toggle {
height: 33px;
width: 159px;
border: 1px solid #E1E1E1;
border-radius: 2px;
background-color: #FFFFFF;
}
.mat-button-toggle:hover {
border-color: #000;
border-radius: 5px;
}

Linking to a page via a button with an href isn't working

When I put a button tag on "sign up" it doesn't take me to the page I set up, but when I remove the button tag, it works.
Buttons with href won't work. Especially on the "sign up" button. But the other buttons are working. Does anybody know what the problem is?
.button {
background-color: #4CAF50;
/* Green */
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
width: 70px;
height: 30px;
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: #ccd9ff;
color: black;
border: 2px solid #555555;
}
.button1:hover {
background-color: #808080;
color: white;
}
.button2 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button2:hover {
background-color: ffcccc;
color: white;
}
.button3 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button3:hover {
background-color: #ff99e6;
color: white;
}
.button4 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button4:hover {
background-color: #ff9999;
}
.button5 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button5:hover {
background-color: #ffb399;
color: white;
}
.button6 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button6:hover {
background-color: #9999ff;
color: white;
}
.button7 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button7:hover {
background-color: #ccccff;
color: white;
}
.button8 {
background-color: #ccd9ff;
color: black;
border: none;
}
.button8:hover {
background-color: #ffffcc;
color: white;
}
<form id="searchbox" action="">
<input id="search" type="text" placeholder="Search Anime">
<button class="button button1" id="submit" type="submit" value="Search">Search</button>
<FONT face="Comic Sans MS" COLOR="#ff4d4d" SIZE=2>Login</FONT> or
<A HREF=register.html style="text-decoration:none">
<button class="button button8" <FONT face="Comic Sans MS" COLOR="#ff4d4d" SIZE=2>Sign Up</FONT><Button>
</A>
</form>
you should close the anchor tag and use quotes around the link
my link
PS use lowercase for tag eg: <a> and attribute eg: href
Try
<input type="submit" class="button button8" value="Sign Up">
Style it via external CSS rather than inline.
I'd say that's because HTML doesn't work that way... I advise you to follow some W3C Tutorial.
Start off here: https://www.w3schools.com/tags/tag_button.asp
Anyway, the main problem I think it's that, in the DOM Tree, you can't have inline elements (such as ) containing block elements (such as )
So with I'd add an onclick attribute, rather than putting the button inside an
Also, to be sure with HTML, always use this syntax:
Note the lowercase, and the quoting marks!

Remove blank spaces between buttons in HTML, CSS

I want to remove blank spaces between the buttons, so that when I for example hover over the NORMAL button, there will be no blank space between it and the HARD button. How can I do that and where do these blank spaces come from?
body {
margin: 0;
}
#stripe {
background-color: white;
text-align: center;
height: 50px;
color: black;
}
button {
border: none;
background: none;
text-transform: uppercase;
height: 100%;
font-weight: 700;
color: black;
letter-spacing: 1px;
font-size: inherit;
transition: all 0.3s;
outline: none;
}
button:hover {
color: white;
background: black;
}
.selected {
color: white;
background: black;
}
<div id="stripe">
<button class="mode">Easy</button>
<button class="mode">Normal</button>
<button class="mode selected">Hard</button>
</div>
Browsers always add spaces between some elements, including buttons. To remove these, you need to set font-size to zero for their parent container. Then, to restore text size inside buttons, set font-size for them.
#stripe {
font-size: 0;
}
button {
font-size: 14px; // Set font size that you need here
}
Either remove the spaces and carriage returns, or put an HTML comment between them.
body {
margin: 0;
}
#stripe {
background-color: white;
text-align: center;
height: 50px;
color: black;
}
button {
border: none;
background: none;
text-transform: uppercase;
height: 100%;
font-weight: 700;
color: black;
letter-spacing: 1px;
font-size: inherit;
transition: all 0.3s;
outline: none;
}
button:hover {
color: white;
background: black;
}
.selected {
color: white;
background: black;
}
<div id="stripe">
<button class="mode">Easy</button><!--
--><button class="mode">Normal</button><!--
--><button class="mode selected">Hard</button>
</div>
Add display: flex; to the parent container
If using bootstrap, can group buttons together by wrapping in div with class="btn-group".
Example for v3.3.7: https://getbootstrap.com/docs/3.3/components/#btn-groups-single
Visually might or might not be what you want. Has rounded corners on left and right ends and straight line between buttons. Can probably restyle.

How to add button inside input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
The community is reviewing whether to reopen this question as of 3 days ago.
Improve this question
How do I visually place a button inside an input element as shown below?
The user should be able to interact with the input as normal. The text shouldn't go behind the button, even when it's long. Focus should work correctly. The form should be accessible and work correctly in screen readers. The whole component should be styleable with CSS, and should be able to easily resize to fit the space available.
How do I accomplish this with modern CSS?
The button isn't inside the input. Here:
input[type="text"] {
width: 200px;
height: 20px;
padding-right: 50px;
}
input[type="submit"] {
margin-left: -50px;
height: 20px;
width: 50px;
}
Example: http://jsfiddle.net/s5GVh/
Use a Flexbox, and put the border on the form.
The best way to do this now (2022) is with a flexbox.
Put the border on the containing element (in this case I've used the form, but you could use a div).
Use a flexbox layout to arrange the input and the button side by side. Allow the input to stretch to take up all available space.
Now hide the input by removing its border.
Run the snippet below to see what you get.
form {
/* This bit sets up the horizontal layout */
display:flex;
flex-direction:row;
/* This bit draws the box around it */
border:1px solid grey;
/* I've used padding so you can see the edges of the elements. */
padding:1px;
}
input {
/* Tell the input to use all the available space */
flex-grow:2;
/* And hide the input's outline, so the form looks like the outline */
border:none;
}
/* remove the input focus blue box, it will be in the wrong place. */
input:focus {
outline: none;
}
/* Add the focus effect to the form so it contains the button */
form:focus-within {
outline: 1px solid blue
}
button {
/* Just a little styling to make it pretty */
border:1px solid blue;
background:blue;
color:white;
}
<form>
<input />
<button>Go</button>
</form>
Why this is good
It will stretch to any width.
The button will always be just as big as it needs to be. It won't stretch if the screen is wide, or shrink if the screen is narrow.
The input text will not go behind the button.
Caveats and Browser Support
There's limited Flexbox support in IE9, so the button will not be on the right of the form. IE9 has not been supported by Microsoft for some years now, so I'm personally quite comfortable with this.
I've used minimal styling here. I've left in the padding to show the edges of things. You can obviously make this look however you want it to look with rounded corners, drop shadows, etc..
.flexContainer {
display: flex;
}
.inputField {
flex: 1;
}
<div class="flexContainer">
<input type="password" class="inputField">
<button type="submit"><img src="arrow.png" alt="Arrow Icon"></button>
</div>
I found a great code for you:
HTML
<form class="form-wrapper cf">
<input type="text" placeholder="Search here..." required>
<button type="submit">Search</button>
</form>
CSS
/*Clearing Floats*/
.cf:before, .cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}
/* Form wrapper styling */
.form-wrapper {
width: 450px;
padding: 15px;
margin: 150px auto 50px auto;
background: #444;
background: rgba(0,0,0,.2);
border-radius: 10px;
box-shadow: 0 1px 1px rgba(0,0,0,.4) inset, 0 1px 0 rgba(255,255,255,.2);
}
/* Form text input */
.form-wrapper input {
width: 330px;
height: 20px;
padding: 10px 5px;
float: left;
font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma';
border: 0;
background: #eee;
border-radius: 3px 0 0 3px;
}
.form-wrapper input:focus {
outline: 0;
background: #fff;
box-shadow: 0 0 2px rgba(0,0,0,.8) inset;
}
.form-wrapper input::-webkit-input-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
.form-wrapper input:-moz-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
.form-wrapper input:-ms-input-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
/* Form submit button */
.form-wrapper button {
overflow: visible;
position: relative;
float: right;
border: 0;
padding: 0;
cursor: pointer;
height: 40px;
width: 110px;
font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma';
color: #fff;
text-transform: uppercase;
background: #d83c3c;
border-radius: 0 3px 3px 0;
text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);
}
.form-wrapper button:hover {
background: #e54040;
}
.form-wrapper button:active,
.form-wrapper button:focus {
background: #c42f2f;
outline: 0;
}
.form-wrapper button:before { /* left arrow */
content: '';
position: absolute;
border-width: 8px 8px 8px 0;
border-style: solid solid solid none;
border-color: transparent #d83c3c transparent;
top: 12px;
left: -6px;
}
.form-wrapper button:hover:before {
border-right-color: #e54040;
}
.form-wrapper button:focus:before,
.form-wrapper button:active:before {
border-right-color: #c42f2f;
}
.form-wrapper button::-moz-focus-inner { /* remove extra button spacing for Mozilla Firefox */
border: 0;
padding: 0;
}
Demo: On fiddle
Source: Speckyboy
This is the cleanest way to do in bootstrap v3.
<div class="form-group">
<div class="input-group">
<input type="text" name="search" class="form-control" placeholder="Search">
<span><button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button></span>
</div>
</div>
This can be achieved using inline-block
JS fiddle here
<html>
<body class="body">
<div class="form">
<form class="email-form">
<input type="text" class="input">
Button
</form>
</div>
</body>
</html>
<style>
* {
box-sizing: border-box;
}
.body {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;
}
.form {
display: block;
margin: 0 0 15px;
}
.email-form {
display: block;
margin-top: 20px;
margin-left: 20px;
}
.button {
height: 40px;
display: inline-block;
padding: 9px 15px;
background-color: grey;
color: white;
border: 0;
line-height: inherit;
text-decoration: none;
cursor: pointer;
}
.input {
display: inline-block;
width: 200px;
height: 40px;
margin-bottom: 0px;
padding: 9px 12px;
color: #333333;
vertical-align: middle;
background-color: #ffffff;
border: 1px solid #cccccc;
margin: 0;
line-height: 1.42857143;
}
</style>

css on different input classes

hello i have the following problem:
i do check my form for some php error messages.
in case of no error i simply have my css setting:
.wrapper #frame form fieldset ul input {
color: #f23;
font-size: 10px;
height: 18px;
padding-left: 5px;
margin-top: 3px;
outline:none;
}
and my focus settings:
.wrapper #frame form fieldset ul input:focus{
color:#fff;
font-weight: bold;
border: 2px solid #fff;
}
okay, now i changed this line:
<input type="text" id="normal" name="1" value=""/>
with adding the class of error:
<input class="err" type="text" id="normal" name="1" value=""/>
the problem is that my settings just take place for my class details on the input fields but not on my focus settings:
.err {
color: #444444;
font-size: 10px;
width: 180px;
height: 18px;
padding-left: 5px;
outline:none;
background-image: url(../images/error.png);
}
.err input:focus{
color:#f23;
font-weight: bold;
border: 2px solid #f23;
}
so if there is someone who could tell me why this does not work i really would appreciate. thanks a lot.
You have a class of error in your HTML, and in your CSS you've set the class to err; if you use the same name consistently (whichever you choose) it should work.
Your current HTML:
<input class="error" type="text" id="normal" name="1" value=""/>
...and CSS:
.err {
color: #444444;
font-size: 10px;
width: 180px;
height: 18px;
padding-left: 5px;
outline:none;
background-image: url(../images/error.png);
}
.err input:focus{
color:#f23;
font-weight: bold;
border: 2px solid #f23;
}
Also, in your CSS you're selecting an input that's a descendant of an element with the err class-name, not an input element with that class-name. So, altogether you should use something like:
<input class="err" type="text" id="normal" name="1" value=""/>
input.err {
color: #444444;
font-size: 10px;
width: 180px;
height: 18px;
padding-left: 5px;
outline:none;
background-image: url(../images/error.png);
}
input.err:focus{
color:#f23;
font-weight: bold;
border: 2px solid #f23;
}