CSS Sprite Not Working in CodeIgniter Submit Button - html

I am trying to do two things:
Replace a regular submit button in my CodeIgniter view (see code below) with a sprite button with roll over effects.
Submit my CodeIgniter form
<input type="submit" name="submit" value="Search" class="button" />
My sprite images (normal and hover states) both do not display using the code above. However, if I comment it out, and replace it with the following, it displays correctly, however I cannot submit my form:
<p class="button"></p>
Here is my css:
.button {
display:block;
width:135px;
height: 35px;
text-indent:-9999px;
}
.button a {
display:block;
width: 100%;
height: 100%;
background:transparent url(../images/button-sprite.gif) no-repeat top left;
outline:none;
}
.button a:hover {
background-position: 0 -35px;
}
What am I doing wrong?
SOLUTION:
Thank you #AdityaSaxena for your alternative solution. I found another solution too:
my.css
.button {
display:block;
width:135px;
height: 35px;
text-indent:-9999px;
background:transparent url(../images/button-sprite.gif) no-repeat top left;
}
.button:hover {
background-position: 0 -35px;
}
my.html
// ...
<input type="submit" name="submit" value="Search" class="button" />
// ...

You are not able to submit the form because you replaced your <input type="submit" /> with an anchor tag. You have to add the capability to submit a form to your <a> tag
.button a was not working because you did not have any <a> tag inside your <input type="submit"> tag which is what was expected when you used .button a
Few changes from the html and js and things will start working for you.
Your new HTML stays intact.
<p class="button"></p>
Your JS / Jquery if you can use it becomes this:
$('.button a').on('click', function(){
$(this).closest('form').submit();
});

Related

Different colored submit button on hover - HTML

I've created two submit buttons:
http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg
http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg
I want the first to show as my standard submit button (dark) and the second (light) to show on hover.
My code is as follows:
<input name="submit" id="submit" type="image" src="http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg" width="314" height="40" value="Sign up" /></div>
CSS is:
submit:hover { background-image: url ('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');
However the on hover image isn't showing, any idea why?
Your CSS selector is invalid for the submit button, you need to reference either the button in your CSS as:
This will style all submit buttons.
input[type=submit] { }
This will style only the element (this case a submit button) with the ID of 'submit'
#submit { }
So for example:
input[type=submit]:hover { background-image: url ('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');
If you want to style all submit buttons with the same background to begin with and same hover effect you should use:
input[type=submit]:hover { background-image: url ('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg'); }
input[type=submit] { background-image: url: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg'); }
You need to drop the src attribute of your input, and use background-image instead in similar manner, as you tried to do on hover. Your attempt failed for two reasons - one you missed hash before referencing your element by it's id (or name), and then even if you make this step right you wouldn't see background image anyway because of src attribute of your input.
You can do it in this simple way:
fiddle
<input type="submit" id="submit" width="314" height="40" value="" />
and:
#submit {
border:0;
width:314px;
height:40px;
background-image: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg');
}
#submit:hover { background-image: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');}
#submit:focus, #submit:active {
outline:none;
}
EDIT:
You also have a closing div at the end of input tag - it's probably leftover from your whole code, but it makes HTML invalid without opening div.
Why not change it to use CSS instead, that way you can re use the styling and update the text within the button without creating a new image.
HTML:
<button type="submit">Start Trial ►</button>
CSS:
button {
background: #4e6ea1;
height: 40px;
width: 200px;
color: #fff;
border: 1px solid #444;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
button:hover {
background: #84a3d9;
}
<input name="submit" id="submit" type="image" src="http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg" onMouseOver="this.src='http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg'" onMouseOut="this.src='http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg'" width="314" height="40" value="Sign up" />
use onMouseOver property
try this.,
<input name="submit" id="submit" type="image" width="314" height="40" value="Sign up" />
input#submit{
background: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg');
}
input#submit:hover {
background: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');
}
By specifying the base image as a src you cannot change it with css, you need javascript to do that. In order to achieve with css you need to do something like this.
<input name="submit" id="submit" type="submit" class="submit" value="Sign up" />
.submit {
background:url(http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg);
text-indent: -9999px;
text-transform: capitalize;
height:40px;
width: 314px;
border:0;
}
.submit:hover{
background:url(http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg);
}
Note: the text transform is for ie7
You have to set the initial image of the button as css-background property aswell insted of defining it as html src attribute.
New HTML (i also added a submit class, dont use IDs for button syling):
<input name="submit" id="submit" class="submit" type="image" width="314" height="40" value="Sign up" /></div>
New CSS (also added the class indicator .):
.submit {
background-image: url ('http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg');
}
.submit:hover {
background-image: url ('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');
}
The problem is that you firstly have to give the button a background-image and then assign a new one when the user hovers it, otherwise it will be hidden behind.
<input name="submit" id="submit" type="image" width="314" height="40" value="Sign up" />
input {
background-image: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-dark.jpg');
}
input:hover {
background-image: url('http://www.workbooks.com/sites/default/files/image/submit-button-2015-light.jpg');
}
Fiddle: http://jsfiddle.net/rdxfye9e/

Image button in html

I'm trying to get a button that has an image on it. I've seen stuff like the following but they don't give you the button press/release effect that a normal button does.
<input type="image" id="saveform" src="logg.png " alt="Submit Form" />
Is there a way to get the button click/release effect but just slap an image inside the button?
Yes there is, by applying a background-image to the button like so:
HTML
<button>Click Me</button>
CSS
button{
background-image: url("YourImageHere");
color: #FFF; //random values
height: 50px; //random values
width: 100px; //random values
}
FIDDLE
.yourButton{
background:url("logg.png") no-repeat;
border:none;
cursor:pointer;
width:40px;
height:10px;
}
If you want to do it with the input button you can try this code:
<input type="image" id="saveform" src="logg.png " alt="Submit Form" />
and your css will look like this:
#saveform {
outline: none; //To remove the blue outline ( the blue line ) when the focus event occurs
}
#saveform:active {
transform: scale(0.9,0.9);
}
However if you do not want to try the with the input tag, you can use this code:
Html:
<button id="saveform" type="submit" value="Submit">Submit</button>
CSS:
#saveform{
background-image: url("SourceOfYourImage");
height: 50px; // Any value
width: 100px; // Any value
}

HTML input type submit strange behavior after adding a custom class

I got a form on my page with a submit button:
<form id="searchForm">
<input id="searchTerm" type="text" name="searchterm" class="search-field"/>
<input type="submit" value="Submit"/>
</form>
When I click on the button I sucessfuly submit the form and trigger jQuery function:
$('#searchForm').submit(function() {
some code...
});
With no reason, when I add a custom class to change the button appearance it stops trigering submit function, as it was before:
<input type="submit" value="Submit" class="submit-search"/>
The class adds the folowing properties:
#search .main .search-bar .submit-search {
margin-top: 2.3rem;
}
#search .main .search-bar .submit-search {
background-color: transparent;
background-image: url("../../css/sprites/search-submit-icon.png");
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
border: medium none;
display: inline-block;
font-size: 0;
height: 20px;
margin: 10px;
outline: medium none;
padding: 0;
width: 20px;
}
I will appreciate any ideas to make this working.
You have two functions executing when the button is clicked. First it executes the function checkTextField() which is on the click event then when it finishes it executes, other function which is on the form submit event. I think this is not a good idea. You should remove the onclick function and add it to the on form submit.

Adding an image to submit button using CSS

I'm attempting to use CSS in order to make a sumbit button containing an image. Here's the code:
HTML
<input type="submit" id="search" name="submit" alt="search" >
CSS
input#search{
background:url(../search-icon.png);
background-repeat: no-repeat;
width:40px;
height:40px;
}
This returns this submit button, but I don't want the word 'submit' or the gray square box to appear.
If anyone could suggest what the problem might be, it would be greatly appreciated.
The gray box is caused by a default border being added to the submit buttons. Whereas the submit text is the default value for the button.
HTML:
<input type="submit" id="search" name="submit" alt="search" value="">
CSS:
input#search {
background:url(../search-icon.png);
background-repeat: no-repeat;
width:40px;
height:40px;
border: 0;
}
Add value with empty string to the input:
<input type="submit" id="search" name="submit" alt="search" value="">
instead of input type="submit" you can use input type="image"
use this one line code
<input type="image" src="submit.gif" alt="Submit" width="48" height="48">
see DEMO
You can use CSS text-indent to move the text away:
input#search {
background:url(../search-icon.png);
background-repeat: no-repeat;
width:40px;
height:40px;
text-indent:-999px
}
https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent
Set blank Value of the input type submit as shown below :
<input type="submit" id="search" name="submit" alt="search" value="" >
try this
input#search {
background:url(../search-icon.png) no-repeat;
width:40px;
height:40px;
text-indent:50px;
overflow:hidden;
}
<!DOCTYPE html>
<html>
<head>
<style>
input.search{
background-image:url(url.jpg);
text-indent:-9999px;
width: 100px;
height: 30px;
border:2px solid rgb(0,102,153);
}
</style>
</head>
<body>
<input type="submit" class="search" alt="search">
</body>
</html>
I find this to be the most complete solution:
#submitbutton {
background-image: url(http://paulabrown.net/search-button-png-210.png);
background-repeat: no-repeat;
height: 24px; // height of image
width: 24px; // width of image
padding: 0;
border: none; // get rid of grey border
color: transparent; // hide the text (without indenting it to hell)
background-color: transparent;
outline: none;
display: block; // Ensure block element to apply this to inline-elements
}
html: <input type ="submit" value ="" class="search-button"/>
CSS:
.search-button
{
background-image: url("/images/search.png");
background-repeat: no-repeat;
min-width: 52px;
min-height: 20px;
width:52px;
height: 20px;
border:0;
}

How to style the iOS6 file input control?

I am glad the file input control for files has finally arrived to the iPhone with iOS 6.
However, the display looks kind of odd. Does anyone know ways to style the control?
Simple, you can hide the element and you can fire their click event.
HTML:
<input type="file" class="uploader" />
<u>Choose file</u>
CSS:
input.uploader {
visibility:hidden;
height: 0;
}
u {
display: block;
margin: 5px;
padding: 15px;
text-align: center;
background: #ddd;
border-radius: 6px;
}
JS (with JQuery):
$('u').click(function(){
$('input[name=photo]').trigger('click');
});
Sample: http://uploader.gokercebeci.com/
Here's the OK solution for iOS:
HTML:
<form enctype="multipart/form-data" method="POST" accept-charset="UTF-8">
<input accept="image/jpeg" name="pic" id="pic" type="file">
<a onmousedown="myClick();">
Choose a new picture
</a>
<br>
<input value="put up the picture" type="submit">
</form>
CSS:
#pic {
display:none;
}
Javascript:
function myClick() {
document.getElementById('pic').click();
}
Or on CSSdeck:
http://cssdeck.com/labs/kmyjvuwb
This works fine in current Firefox and Chrome, too, but alas, not in IE (the file is not uploaded!)...