Jump to content

Help using an image as a button background

KingUnicorn

So I'm getting into html and css code right now and I'm using what i know to make a homepage in Chrome that is essentially a bookmarks bar with a bigger, decent looking UI. The only reason I started doing this was because I thought it would be a cool test of my skills. anyways, right now I'm trying to make the links as buttons. I know that is easy enough, but what I'm having trouble with is I want to have an image as the background of the button with the text on top. For the button itself I used this css code to format it:

		a:link, a:visited {
		background-color: #0012b5;
		color: #00ffcb;
		border: 3px solid #00ffcb;
		padding: 30px 40px;
		font-family: verdana;
		font-size: 200%;
		text-align: center;
		text-decoration: none;
		display: inline-block;
	}

	a:hover, a:active {
		background-color: #00ffcb;
		color: black;
	}

this made the button and the text the way I wanted it. Everything works when it's like this. Now I know I could simply make the image itself the link, but the images I want to use are not all the same aspect ratio, so when I did that with my first site it was not uniform or consistent. So I'm trying buttons this time. The thing I'm having trouble with is what to use to make the background of the button a specific image that changes whenever i hover over the image (so image A is shown when the button is inactive, and image B is shown when I hover over the image). I have no idea how to do this. I tried the background-image tag, but that just screws up the button. Is there anything I can use? Or am I using the tag wrong? As I said earlier I am fairly new to HTML and CSS, so I would love some help with this. Thanks in advance for any help provided!

The smartest idiot you will ever find

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, M.Yurizaki said:

Have you tried playing around with the background-size and background-position properties?

 

http://www.w3schools.com/cssref/css3_pr_background.asp

After messing around some it does keep the size of the box from being messed up, however it still doesn't show the image. Oh and if i forgot to say it earlier, I am trying to use the class function (which I know how to use) to make these since I am trying to make each button a link to a different site, and the best way I could think of doing that was make a class for each site with its own image, coding each class into my css stylesheet to keep the html file uncluttered. If you want I could post all of the code and the result on my site

The smartest idiot you will ever find

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Potato_King said:

After messing around some it does keep the size of the box from being messed up, however it still doesn't show the image. Oh and if i forgot to say it earlier, I am trying to use the class function (which I know how to use) to make these since I am trying to make each button a link to a different site, and the best way I could think of doing that was make a class for each site with its own image, coding each class into my css stylesheet to keep the html file uncluttered. If you want I could post all of the code and the result on my site

Just the snippet where the buttons are is fine.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×