DZone Forums
Go Back   DZone Forums > Community > Design & Usability > CSS & HTML
Reload this Page Link with image and text centered vertically
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jun 2008
Default Link with image and text centered vertically - 06-11-2008, 10:12 AM

Hi, I'm trying to create a link with an image and a text. I want the text vertically aligned with the image (if you don't make it explicity, the text appears aligned to the bottom of the image). I get it only this way:

.myButton {
color: black;
font-family: Verdana;
font-size: 11px;
text-decoration: none;
white-space: nowrap;
}

.myButton #buttonLabel {
position: absolute;
padding-top: 6px;
padding-bottom: 6px;
padding-left: 4px;
}

<a href="x" class=myButton>
<img src="image.gif"/>
<span id="buttonLabel">LabelText</span>
</a>

But, as the inner span has position absolute, it is out of the normal flow of elements, and when I want to have a number of these links in the same row, only the images take it place one after another, but the texts overlap one over another.

Is there any other way to do this, avoiding this problem?

Thanks
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Sep 2008
Default One solution - 09-09-2008, 11:51 AM

Code:
.myButton {
		position: relative;   /* position parent container so children are relative to me */
		width: 400px;         /* positioned elements should have width */
		height: 400px;        /* positioned elements should have height */	
		float: left;          /* so that multiple instances go next to each other */
		
		/* setting up font styles */
		color: black;
		font-family: Verdana;
		font-size: 11px;
		text-decoration: none;
		}

	.myButton img, .myButton p {
		position: absolute;  /* position is absolute, relative to the parent a.myButton tag */
		top: 0px;            /* top of element should be 0px from parent element top */
		border: none;        /* remove border (specifically on img), just looks better */
	}
	.myButton p {
		left: 310px;        /* assumes images are 300px wide */
		margin-top: 0px;    /* removes default top margin on p */
	}

Code:
<a href="#" class="myButton">
	<img src="image.jpg"/>
	<p>This is a long explaination of the image on the left.</p>
	</a>
	<a href="#" class="myButton">
	<img src="image.jpg"/>
	<p>This is a long explaination of the image on the left.</p>
	</a>
I commented the code, so it should be obvious what I am doing. However, if you have any questions just let me know.

Jeremy A. Snyder
snydersoft.com | Sharing Web Development Information
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shortcut image svdnstee Java 3 01-22-2009 07:48 AM
Paste image from clipboard into PackageExplorer nawa Eclipse 0 10-31-2008 11:00 AM
How to enable 2 features in Eclipse (list functions in file & link to function) AtomicPenguin Eclipse 0 09-25-2008 03:58 PM
.Raw Image display mcmmoreira Java 1 09-23-2008 08:22 AM
How to link folders between projects? netverde Eclipse 0 03-07-2008 10:47 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com