How can I create a button with an image? - html

I have an image that i want to use as a button on my page that links to other pages. I want to make it in a way that I can use small and large texts on it.
The image in question:
I have tried something but can go no where with it.
a {
background:url(http://i.imgur.com/8Isga60.png);
background-size:contain;
background-repeat:no-repeat;
display:inline-block;
padding:30px 100px;
height:20px;
color:black;
font-size:16px;
}
JS Fiddle

I would recommend you drop the image idea... that concept is very 2005. With today's CSS you can easily recreate that image with pure CSS, which then is much more flexible.
If you Google "CSS button generator" you will find many online tools that help you with that... i.e. http://www.cssbuttongenerator.com/
Here is an example I did in 10 seconds and just copied the CSS they provided... granted it is a little convoluted, but it certainly works:
<style type="text/css">
.classname {
-moz-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
-webkit-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
box-shadow:inset 0px 1px 0px 0px #bbdaf7;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #79bbff), color-stop(1, #378de5) );
background:-moz-linear-gradient( center top, #79bbff 5%, #378de5 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#378de5');
background-color:#79bbff;
-webkit-border-top-left-radius:20px;
-moz-border-radius-topleft:20px;
border-top-left-radius:20px;
-webkit-border-top-right-radius:20px;
-moz-border-radius-topright:20px;
border-top-right-radius:20px;
-webkit-border-bottom-right-radius:20px;
-moz-border-radius-bottomright:20px;
border-bottom-right-radius:20px;
-webkit-border-bottom-left-radius:20px;
-moz-border-radius-bottomleft:20px;
border-bottom-left-radius:20px;
text-indent:0;
border:1px solid #84bbf3;
display:inline-block;
color:#ffffff;
font-family:Arial;
font-size:15px;
font-weight:bold;
font-style:normal;
height:50px;
line-height:50px;
width:100px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #528ecc;
}
.classname:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff) );
background:-moz-linear-gradient( center top, #378de5 5%, #79bbff 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#378de5', endColorstr='#79bbff');
background-color:#378de5;
}.classname:active {
position:relative;
top:1px;
}</style>

You could almost do it in CSS3: JSFiddle Demo
.btn {
margin:10px;
color:white;
font-size:16px;
border:4px solid #c5c7c9;
border-radius: 50px 50px;
display:inline-block;
/* Drop shadow */
-webkit-box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.68);
-moz-box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.68);
box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.68);
/* Gradient Background */
background: rgb(78,186,234); /* Old browsers */
background: -moz-linear-gradient(left, rgba(78,186,234,1) 0%, rgba(0,121,183,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(78,186,234,1)), color-stop(100%,rgba(0,121,183,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(78,186,234,1) 0%,rgba(0,121,183,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(78,186,234,1) 0%,rgba(0,121,183,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(78,186,234,1) 0%,rgba(0,121,183,1) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(78,186,234,1) 0%,rgba(0,121,183,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4ebaea', endColorstr='#0079b7',GradientType=1 ); /* IE6-9 */
}
/* Button Sizes. */
.btn.large { padding:30px 60px; }
.btn.small { padding:10px 30px; }
HTML
my text here
my text here
my text here long text goes here

I think you will have to split the image, as If you try to repeat it using it as a complete image, it will also repeat the rounded parts. So take the left and right, and a pixel from the center. See this answer for reference Button using three (3) background images css
The old school version is something like using three classes for left and right and one for center with the repeating background.Create button using 3 images
Now, as mentioned in the comments, unless you are completely decided on the background images part, a pure CSS solution will probably work better.

Try this:
a{
background:url(http://i.imgur.com/8Isga60.png) no-repeat center;
...
}
However it moves the button too. jsfiddle
You should really look into CSS buttons instead of using images. Try CSS Button Generator

The problem is the left & right padding, Why not separate the link and the text so it's easy to center the content?
(edit: jsfiddle )
<p><a class="sol" href="http://imgur.com/8Isga60"><span>Does not work with larger text</span></a></p>
a.sol {
background:url(http://i.imgur.com/8Isga60.png);
display:inline-block;
padding:30px 0px;
width: 243px;
height:20px;
color:white;
font-size:16px;
text-align: center;
}

Related

Multiple color background HTML

I'm trying to create a multiple color background to implement this:
And right now I managed to do this:
What I did:
Desired Background:
I'm trying to do it using gradients, but it seems that it's not possible to combine two gradients to do that. (It's possible to do other things, but not this).
Is there a way to implement this backgorund?
Thanks!
Try this (adjust the percentage and colors as your needs):
.yourdiv{
background: #ffffff;
background: -moz-linear-gradient(top, #ffffff 0%, #ffffff 70%, #f1f1f1 70%, #f1f1f1 100%);
background: -webkit-linear-gradient(top, #ffffff 0%,#ffffff 70%,#f1f1f1 70%,#f1f1f1 100%);
background: linear-gradient(to bottom, #ffffff 0%,#ffffff 70%,#f1f1f1 70%,#f1f1f1 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#f1f1f1',GradientType=0 );
}
DEMO HERE
i am guessing u need the darker grey section in the desired output to be shown? if so i would suggest to divide it into sections and give individual background.
if u can post some code. i would be happy to help.
Okay, not sure if this is exactly what you want but this is how I'd do psd to css/html. See screen shot below.
Also a WORKING DEMO HERE
Just wrap the whole card in a div and apply a left border would do the trick.
border-left-width: 8px;
border-left-color: rgba(10, 255, 80, 0.75);
border-radius: 5px;
You may remove the box shadow if you don't want, just feel move active with it.
At the end, I managed to do it with this:
This for the GREEN part:
.assignment-item {
padding: 5px 5px 0px 10px !important;
margin:15px auto;
border-radius: 8px;
background: linear-gradient(to right, #4f8b2b 0%,#4f8b2b 2%,#ffffff 2%,#ffffff 100%, transparent) !important;
}
This for the GREY part:
.assignment-item:before{
position:absolute;
z-index:-1;
bottom:0;
left:2%;
width:100%;
height:25%;
content:"";
background-color:#f2f2f2;
}
Here is the result:

CSS how to make icons look like they are inside the backround

I dont kmow how to explain this, if this is a design question please correct me. Look at the following facebook header.
That friend requests icon and sort look like they are inside the background, how do i do this with css?
You could do something like this (Just whipped it up, so it's not perfect).
I used colours from the Facebook image you provided.
Here is what I did:
HTML:
<div id="container">
<div id="inset"></div>
</div>
CSS:
#container{
height:200px;
width:200px;
background:#48639b;
}
#inset{
background:#31497e;
height:50px;
width:50px;
box-shadow:inset 0px 0px 5px #1f2f50;
}
JSFiddle -- Try one
JSFiddle -- Try two
The JSFiddle as a few extra styles to put #inset more into the container, but they don't affect the over style of the inset.
You can accomplish the sort button styling, by using box-shadow - and inset to get the shadow inside the button. As well as border-radius for rounding the corners.
HTML
button
CSS
body { background:#4b669d; padding:40px;
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;}
a {
display:inline-block;
font-size:12px;
padding:0 20px;
margin:10px;
height:30px;
background:#435c91;
border:1px solid #2a3349;
text-align:center;
color:#fff;
line-height:26px;
text-decoration:none;
border-radius:5px;
/* this is the inner shadow and drop shadow */
-webkit-box-shadow:inset 0 0 3px 2px rgba(0,0,0,0.15), 1px 1px 0px 1px rgba(255,255,255,0.3);
box-shadow:inset 0 0 3px 2px rgba(0,0,0,0.15), 1px 1px 1px 0px rgba(255,255,255,0.3);
/* gradient - from http://www.colorzilla.com/gradient-editor/ */
background: rgb(93,114,163); /* Old browsers */
background: -moz-linear-gradient(top, rgba(93,114,163,1) 0%, rgba(46,72,128,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(93,114,163,1)), color-stop(100%,rgba(46,72,128,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(93,114,163,1) 0%,rgba(46,72,128,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(93,114,163,1) 0%,rgba(46,72,128,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(93,114,163,1) 0%,rgba(46,72,128,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(93,114,163,1) 0%,rgba(46,72,128,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5d72a3', endColorstr='#2e4880',GradientType=0 ); /* IE6-9 */
}
Obviously it requires a bit more tweaking, but hopefully that should be a starting point.
JSFiddle Demo 2 - now with gradient background and a drop-shadow too.
and http://jsfiddle.net/53fWz/6/
Use multiple box-shadows to give the embossed effect.
box-shadow:inset 0 1px 1px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.3);
http://jsfiddle.net/Em97N/2/
You should color the image, with a more dark color than the forground. Simple design. Maybe add a black border arround it.

HTML button always one place

I have HTML code with background image,which is man's head.I have html button on man's eye,and I want when browser windows resizes,button be always on eye,this is my code.
Please help me,thanks a lot to help me.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post</title>
</head>
<body>
<div>
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<img id="bgimage" src="heroes.jpg"/>
<div id="content">
<p align="center"><input type="submit" class="butt" onclick="dosomething();"/></p>
</div>
</td>
</tr>
</table>
</div>
<style>
body,html{margin:0;padding:0; height:100% width:100%}
#bgimage{ position:fixed; left:0; top:0; z-index:1;height:100%; width:100%;}
#content{position:absolute;left:0; top:0; z-index:70; height:100%; width:100%;}
.butt {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #3c4fd9;
display:inline-block;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}.butt:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}.butt:active {
position:relative;
top:1px;
}
.butt{
margin-top:260px;
margin-right:190px;
}
.butt{
}
</style>
</body>
</html>
button.classname{
position:fixed;
top:value; /*set a value so that it comes on eye horizontally*/
left:value; /*set a value so that it comes on eye vertically*/
}
Fixed position and absolute position work in different way. If you use fixed position ,body will be the parent of the item but absolute positioned item can have user defined parent( just give parent element a position property.)
So, if you want to keep the man and the eye button together you have to use same parent. use same position for both man and eye (fixed or absolute) having same parent.
second thing is, you are resizing the man's head by using width: 100% and height: 100%; so, if you want the eye button also change the position use percentage in position (eg. top: 50%). have a look at http://css-tricks.com/snippets/css/exactly-center-an-imagediv-horizontally-and-vertically/ . It might help you.
I tried to not make that many adjustments to your code as possible to make this solution as easy to implement as possible, but I have done what you're asking in the following way.
Put this in the "head" section of your HTML:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
HTML:
<img id="bgimage" src=""/>
<div id="content">
<input type="submit" class="butt" onclick="dosomething();"/>
</div>
CSS:
body,html{ margin:0;padding:0;height:100%;width:100%}
#bgimage{
position:fixed;
left:0;
top:0;
z-index:1;
height:100%;
width:100%;
}
#content{
position:absolute;
left:0;
top:0;
z-index:70;
height:100%;
width:100%;
}
.butt {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #3c4fd9;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}
.butt:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}
.butt:active {
position:relative;
top:1px;
}
jQuery:
$('.butt').css({
"position" : "absolute",
"left" : "39%",
"top" : "41%"
});
to put the jQuery in your HTML file just copy and paste this:
<script type="text/javascript">
$(document).ready(function(){
$('.butt').css({
"position" : "absolute",
"left" : "39%",
"top" : "41%"
});
)};
</script>
This isn't perfect on all resolutions, you might have to tweak the percentages in the jQuery, the only alternative is to create a CSS using multiple #media queries to adjust with every screen size.

inline-block appearing wider in Firefox/Safari than Chrome, spilling over line

I made this site. On Chrome (v24.0), everything appears as intended. When I look at it in Safari or Firefox, the layout breaks: the links "view cart" and "checkout" in the top right spill over to an extra line. It's hard to describe, but compare how they look in Chrome (correct) vs Firefox and Safari (wrong) and it should be obvious what I mean.
How can I fix this? Everything I've tried that successfully solves the problem in Firefox and Safari just breaks it in Chrome.
My current CSS (Sass):
.account-links {
font-size: 0;
}
.account-links a {
box-sizing: border-box;
width: 90px;
margin: 0px;
font-size:9pt;
-moz-box-shadow:inset 0px 0px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 0px 0px 0px #ffffff;
box-shadow:inset 0px 0px 0px 0px #ffffff;
background:-webkit-gradient( linear,
left top, left bottom,
color-stop(0.05, #f9f9f9),
color-stop(1, #e9e9e9) );
background:-moz-linear-gradient( center top,
#f9f9f9 5%, #e9e9e9 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f9f9f9', endColorstr='#e9e9e9');
background-color:#f9f9f9;
border-top:1px solid #dcdcdc;
border-bottom:1px solid #dcdcdc;
&:first-child {
border-right:1px solid #dcdcdc;
}
display:inline-block;
color:#666666;
font-family:arial;
font-weight:bold;
padding: 5px 0px;
text-decoration:none;
text-shadow:0px 1px 0px #ffffff;
&:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #e9e9e9), color-stop(1, #f9f9f9) );
background:-moz-linear-gradient( center top, #e9e9e9 5%, #f9f9f9 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e9e9e9', endColorstr='#f9f9f9');
background-color:#e9e9e9;
}
&:active {
position:relative;
top:1px;
}
}
That's because you're using unprefixed box-sizing for #shop-meta .account-links a. Add -moz-box-sizing: border-box and -webkit-box-sizing: border-box and it should work as intended.
Edit: Actually I've found that there's some bug in Safari (using v5.1.7 for Windows) that prevents box-sizing from working properly. The solution for that browser is to set float: left on .account-links a. You don't need -webkit-box-sizing.
I have run into issues with this a few times with Chrome. Most of the time I can figure it out but a few times I've had to resort to using this: css_browser_selector.js
Basically it allows you to write css like this:
.gecko .account-links a{}
Which would then apply that css to browsers using the gecko engine (i.e. Firefox). I use it on several production sites, (mostly for IE but once or twice for Firefox as well) and I haven't had any issues with it.
Which means that you can use your solutions for Firefox and Safari without breaking what's working in Chrome.

How to maintain browser compatability with Gradient in css?

I am developing a website using html , css and javascript . The buttons display differently in every browser . Here are the screenshots for different browser of the same page :
Internet Explorer :
Firefox :
I actually intend it to display as it displays in firefox . Here Some of the css code i am using :
#button{
float: left;
width: 500px;
height: 50px;
line-height: 50px;
background-color: #06C;
padding-left: 20px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
-webkit-box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);
-moz-box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);
box-shadow: 0px 1px 1px 0px rgba(255,255,255, .2), inset 0px 1px 1px 0px rgb(0,0,0);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, #60B842),
color-stop(0.85, #7FD13D)
);
background-image: -moz-linear-gradient(
center bottom,
/* change these to change the button colors */
#B58515 0%,
#DC9E1F 85%
);
/* change this to change the text color and font type */
color:#fff;
font-family:arial,helvetica,sans-serif;
font-size:17px;
font-weight:bold;
text-shadow:1px 1px 1px #4c9434;
}
#button:hover{
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, #6DD14B),
color-stop(0.85, #85DB40)
);
background-image: -moz-linear-gradient(
center bottom,
/* change these colors to change the mouse hover colors */
#E17100 0%,
#FF9326 85%
);
box-shadow:0 2px 0 #5EA839;
}
There maybe some issues with using the gradient . Can someone suggest me any changes or another ways to code so that the webpage looks the same in different browsers ?
I usually use Colorzilla's Ultimate CSS Gradient Generator to generate cross browser CSS gradient code.
Apart from -webkit-gradient() and -moz-gradient() you also need to use the prefixes for IE and other browsers.
Example:
#linearBg2 {
/* fallback */
background-color: #1a82f7;
background: url(images/linear_bg_2.png);
background-repeat: repeat-x;
/* Safari 4-5, Chrome 1-9 */
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1a82f7), to(#2F2727));
/* Safari 5.1, Chrome 10+ */
background: -webkit-linear-gradient(top, #2F2727, #1a82f7);
/* Firefox 3.6+ */
background: -moz-linear-gradient(top, #2F2727, #1a82f7);
/* IE 10 */
background: -ms-linear-gradient(top, #2F2727, #1a82f7);
/* Opera 11.10+ */
background: -o-linear-gradient(top, #2F2727, #1a82f7);
}
Source
Read more here
Note that IE 9 and earlier do not support gradient.
What's happening is that IE ignores your gradient css completely. You have to add a 'filter' in order for the gradient to appear in IE.
This page will help you create a cross-browser gradient.
All browser Support gradient property
use this
background: -moz-linear-gradient(top, white, #1a82f7);/*Mozila*/
background: -o-linear-gradient(top, white, #1a82f7); /*opera*/
background: -webkit-linear-gradient(top, white, #1a82f7);/*Chrome and safari*/
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='white', EndColorStr='#1a82f7'); /*IE*/
Here is a set of CSS gradients that will be useful for you for cross-browser compatibility:
/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);
/* Mozilla Firefox */
background-image: -moz-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);
/* Opera */
background-image: -o-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);
/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #FFFFFF), color-stop(1, #00A3EF));
/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(top left, #FFFFFF 0%, #00A3EF 100%);
/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to bottom right, #FFFFFF 0%, #00A3EF 100%);