I want to use a Submit Button Image instead of the standard Button. I searched on Google and SO and got a few different ways.
Which is the right way of using an Image as a Submit Button ?
Also i would want to add three states for the button - normal, hover, onclick
What i tried
HTML
<input type="submit" value="Subscribe">
CSS
input[type=submit] {
background:url(../images/btn-subscribe.gif) none;
text-indent:-9999px;
width:109px;
height:41px;
}
What shows up
What it should Display
Edited:
I think you are trying to do as done in this DEMO
There are three states of a button: normal, hover and active
You need to use CSS Image Sprites for the button states.
See The Mystery of CSS Sprites
/*CSS*/
.imgClass {
background-image: url(http://inspectelement.com/wp-content/themes/inspectelementv2/style/images/button.png);
background-position: 0px 0px;
background-repeat: no-repeat;
width: 186px;
height: 53px;
border: 0px;
background-color: none;
cursor: pointer;
outline: 0;
}
.imgClass:hover{
background-position: 0px -52px;
}
.imgClass:active{
background-position: 0px -104px;
}
<!-- HTML -->
<input type="submit" value="" class="imgClass" />
<input type="image" src="path to image" name="submit" />
UPDATE:
For button states, you can use type="submit" and then add a class to it
<input type="submit" name="submit" class="states" />
Then in css, use background images for:
.states{
background-image:url(path to url);
height:...;
width:...;
}
.states:hover{
background-position:...;
}
.states:active{
background-position:...;
}
<INPUT TYPE="image" SRC="images/submit.gif" HEIGHT="30" WIDTH="173" BORDER="0" ALT="Submit Form">
Where the standard submit button has TYPE="submit", we now have TYPE="image". The image type is by default a form submitting button. More simple
It's very important for accessibility reasons that you always specify value of the submit even if you are hiding this text, or if you use <input type="image" .../> to always specify alt="" attribute for this input field.
Blind people don't know what button will do if it doesn't contain meaningful alt="" or value="".
You have to remove the borders and add a background image on the input.
.imgClass {
background-image: url(path to image) no-repeat;
width: 186px;
height: 53px;
border: none;
}
It should be good now, normally.
Related
Is it possible to change background image of page by click on button using only CSS? I have 6 buttons, and I want to change background image of whole page to be changed on button click.
Is it possible with only css? If yes, then how?
This is perfectly easily possible using only CSS and HTML.
http://codepen.io/anon/pen/KpmPYO
input[name="bg-change-control"] {
display: none;
}
body {
margin: 0;
}
#page {
background: url(http://lorempixel.com/1000/700) no-repeat 0 0;
background-size: cover;
height: 100vh;
}
label {
-moz-appearance: button;
-webkit-appearance: button;
}
#cb1:checked ~ #page{
background-image: url(http://lorempixel.com/800/600);
}
#cb2:checked ~ #page{
background-image: url(http://lorempixel.com/640/480);
}
#cb3:checked ~ #page{
background-image: url(http://lorempixel.com/1024/768);
}
<input type="radio" name="bg-change-control" id="cb1" />
<input type="radio" name="bg-change-control" id="cb2" />
<input type="radio" name="bg-change-control" id="cb3" />
<div id="page">
<label for="cb1">BG 1</label>
<label for="cb2">BG 2</label>
<label for="cb3">BG 3</label>
</div>
This is possible with pure CSS and HTML. No need to use Javascript and Jquery.
Try this
HTML:
<input type="button" value="Click" class="click">
<div class="background1"></div>
CSS:
.background1 {
background: url("http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg") no-repeat; width:500px; height:500px
}
.click:focus ~ .background1 {
background: url("http://i.dailymail.co.uk/i/pix/2015/01/06/2473100D00000578-2898639-Photographer_Andrey_Gudkov_snapped_the_images_on_the_plains_of_t-a-20_1420546215677.jpg") no-repeat; width:500px; height:500px
}
Hope it will fullfil your requirement.
That would be nice, but no.
You don't need that hard a function, though. Simply attach the background change with the rest of the functionality of the button. I recommend in this case that you just add the background image as css inline with your js, because 6 classes of images can go wrong easy.
I would like to align text to the left side and the input box to the right side.
This is how my site looks like and this is how it should be: [PICTURE REMOVED]
However, I did what I wanted by using div tag inside a div tag, so, if I give background colour to it, this is how it looks like:
The problem is, after green (on the grey side) I would like to echo errors. But because of the div width of the green area, I cannot do that. Error goes under input box. So, I wonder how can I be able to show form like I did in pictures but at the same time able to show errors on the right side, as well.
So, the script calls javascript plugin (http://jqueryvalidation.org). And this plugin add error right after input box, when it sees a problem. That's why I am not able to put the errors in another div tag.
error will appear in this class: "label.error". If there is way to make this class "don't care fixed width" in css. That would work.
Basicly what you want to do is create a container <div /> element and put 2 <div /> elements inside it. Since you didn't give any code, I can only give you an example:
#container {
width: 512px;
height: 506px;
border: 3px solid green;
}
#left {
float: left;
width: 250px;
height: 500px;
border: 3px solid red;
display: block;
}
#right {
float: left;
width: 250px;
height: 500px;
border: 3px solid blue;
display: block;
}
<div id="container">
<div id="left">
Form here
</div>
<div id="right">
Errors here
</div>
</div>
This is a UI/UX issue and surprisingly I'm shocked no one mentioned using a table with div's.
Because your picture was removed I can't really compare the UI, but to make this a simple answer for Text to the left and Textbox to the right see below.
(JS is just to show how it does work)
function updateText(){
var txtStrng=document.getElementById("txtTextbox1").value;
document.getElementById("lblText").innerHTML=txtStrng;
}
<form action="" >
<table width="100%" height="71" border="0">
<tr>
<td width="45%"><div align="left"><label id="lblText">Test</label></div></td>
<td width="55%"><div align="right">
<input type="text" name="txtTextbox1" id="txtTextbox1" value="Test" onkeyup="updateText();" />
</div></td>
</tr>
</table>
</form>
I was wondering if there is another way in PHP or HTML to use forms without having to have check marks or radio buttons .. For example , if I just click on a link or picture , it can send data to the other PHP file according specified in form action ... I'd like to know if I can just make picture icons send data to the other php page in form action without having to use radio buttons .. but I guess if someone only has to choose one icon from many available .. radio buttons could be the only option available or am I wrong ?
I like to use the button element. Throw in a type="submit", and you have yourself a party.
Demo: http://jsfiddle.net/RnYeg/
HTML
<form method="post" action="">
<button type="submit" name="animal" value="pig">Go</button>
</form>
CSS
button {
background: transparent url(http://lorempixel.com/output/animals-q-c-200-200-6.jpg) 0 0 no-repeat;
border: none;
cursor: pointer;
height: 200px; width: 200px;
}
Alternatively, you could just use an img tag:
Demo: http://jsfiddle.net/umuaU/2/
HTML
<form method="post" action="">
<button type="submit" name="animal" value="pig"><img src="http://lorempixel.com/output/animals-q-c-200-200-6.jpg" alt="Pig" /></button>
</form>
CSS
button {
background: none;
border: none;
cursor: pointer;
margin: 0;
padding: 0;
}
I want a new page to be opened when a button is pressed. Here is my code so far:
<input name="newThread" type="button" value="New Discussion" onclick="window.open('Political/Thread/thread_insert.php')"/>
It fails, however, ..I think the path is incorrect, but I dont know why..cause it is the correct directory path...
This will open a new tab/window (depending on the user's settings):
<a class="button" href="Political/Thread/thread_insert.php" target="_blank">New Discussion</a>
To make this "a button":
a.button {
border: 1px solid #808080;
background: #a0a0a0;
display: inline-block;
padding: 5px;
}
Your code is correct (valid and function), you problem is the your path.
Remember that page location is the page inside the web server and relative to the current page location.
So if your web server root is for example c:\wamp\www then the web address test/test.php will look for the real page of c:\wamp\www\test\test.php. However the same address encoded into a page already in a subdirectory will be relative unless it starts with /
So from the page test/test.php in the above example the link to test/test.php will become /test/test/test.php (with a real path of c:\wamp\www\test\test\test.php)
If you have copied the link from another page somewhere this is probably the problem
Try the below code,
<INPUT type="button" value="Click" onClick="window.open('Political/Thread/thread_insert.php','windowname',' width=400,height=200')">
Try this:
<form action="Political/Thread/thread_insert.php" target="_blank" action="post">
<input name="newThread" type="submit" value="New Discussion" />
</form>
Tested and working. You can leave the action empty if you want.
Or
<form action="Political/Thread/thread_insert.php" target="_blank" action="">
<button>New Discussion</button>
</form>
But as said in one of the other answers, you better go with a link and style it like a button. Using javascript or making forms to achieve the same results is just more work and well... bad.
Use this
Join
class="btn
btn is the style class of the button.
And f you want a direct link to the file and not have to go into an external folder:
Join
I hope this helps
Add below properties to element and it will look exactly same as button
Disable text-decoration for link for better effect
align-items: flex-start;
text-align: center;
cursor: default;
box-sizing: border-box;
padding: 2px 6px 3px;
border-width: 2px;
border-style: outset;
border-image: initial;
-webkit-appearance: push-button;
-webkit-user-select: none;
white-space: pre;
text-rendering: auto;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
margin: 0em 0em 0em 0em;
font: 13.3333px Arial;
I know it's too late but I'm putting it for other people who is looking for the same answer
if(isset($_POST['myButtonName'])){
header("Location:newPage.php");
exit();
}
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<button style="margin-left:5px;" type="submit" class="btn btn-primary" name="myButtonName">Open</button>
</form>
I'm using a jQuery plugin called jQtransform (http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/) which skins HTML form elements like the input box and submit buttons. All is well until I need to use an image as the submit button. I tried the following CSS code but the original button still appears, and not the image.
CSS:
/* this is the submit button */
#search {
width: 32px;
height: 32px;
padding: 0px;
margin: 0px;
border: 0px;
background: transparent url(../images/template/icons/search.png) no-repeat center top;
overflow: hidden;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}
HTML:
<input type="submit" name="search" value="Search" id="search" />
** HTML code looks like it has been processed by the jQuery plugin when viewed in Chrome's 'Inspect Element' feature. The above is the original HTML code as seen when you select 'View Page Source' in Chrome.
What should I do to replace the submit button with my own image? I'm not too good with jQuery...
UPDATE
GREAT! All the answers are working. I must have been thinking too much :)
This should work
<form>
<input type="image" src="[some image]" onsubmit="submitForm();" id="search">
</form>
How about using good old HTML <input type="image" ... />?
<img type="image" src="img src..." id="search" />