Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2006, 09:27 PM   PM User | #1
dantra
Regular Coder

 
Join Date: Aug 2005
Posts: 132
Thanks: 3
Thanked 0 Times in 0 Posts
dantra is an unknown quantity at this point
Align divs horizontally

Normally this wouldn’t be an issue however I seem to be overlooking something.
I would like to align the images horizontally but they align vertically.
As you can see the divs are links which works fine except for the vertical alignment.

Any suggestions on how to get the images to line up next to one another?

Code:
<div id="mylinks">

<h1>More Links</h1>

<h2>Some Of My Links</h2>

<div class="link1"><a href="http://www.mysite1.com" title="Site1" accesskey="d"></a></div>

<div class="link2"><a href="http://www.mysite2.com/site2.htm" title="Site2" accesskey="r"></a></div>

<div class="link3"><a href="http://www.mysite3.com/site3.htm" title="Site3" accesskey="m"></a></div>

</div>

CSS
Code:
#mylinks {
	display: block;
	width: 100%;
	border: none;
	margin: 0 auto;
}

.link1 {
	background: url(../images/site1.jpg) no-repeat;
	margin-top: 25px;
	margin-left: 0px;
	width: 190px;
	height: 61px;
}

.link1 a {
	display:block;
	width:100%; 
	height:100%; 
	font-size:0;
}
* html #link1 a {
	display: inline;
	display: block;
}

.link2 {
	background:url(../images/site2.jpg) no-repeat;
	margin-top: 0px;
	margin-left:0px;
	width: 190px;
	height: 61px;
}

.link2 a {
	display:block;
	width:100%; 
	height:100%; 
	font-size:0;
}

* html #link2 a {
	display: inline;
	display: block;
}

.link3 {
	background:url(../images/site3.jpg) no-repeat;
	margin-top: 0px;
	margin-left:0px;
	width: 190px;
	height: 61px;
}

.link3 a {
	display:block;
	height:61px;
	width:100%; 
	font-size:0;
}

* html #link3 a {
	display: inline;
	display: block;
}
dantra is offline   Reply With Quote
Old 12-09-2006, 09:51 PM   PM User | #2
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello dantra,
Did you try floating them?
Like this
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
	margin: 0px;
	padding: 0px;
}
#mylinks {
	display: block;
	width: 100%;
	border: none;
	margin: 0 auto;
}

.link1 {
	background: url(../images/site1.jpg) no-repeat;
	margin-left: 0px;
	width: 190px;
	height: 61px;
	float: left;
}

.link2 {
	background:url(../images/site2.jpg) no-repeat;
	margin-top: 0px;
	margin-left:0px;
	width: 190px;
	height: 61px;
	float: left;
}


.link3 {
	background:url(../images/site3.jpg) no-repeat;
	margin-top: 0px;
	margin-left:0px;
	width: 190px;
	height: 61px;
	float: left;
}
       

</style>
</head>

<body>
<div id="mylinks">

<h1>More Links</h1>

<h2>Some Of My Links</h2>

<div class="link1"><a href="http://www.mysite2.com/site1.htm">My site</a></div>

<div class="link2"><a href="http://www.mysite2.com/site2.htm">Link 2</a></div>

<div class="link3"><a href="http://www.mysite3.com/site3.htm">Link 3</a></div>

</div>
</body>
</html>
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 12-09-2006, 10:00 PM   PM User | #3
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
And even simpler...since small code is always good:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
	margin: 0px;
	padding: 0px;
}
#mylinks {	
	width: 100%;	
}
.link {
	margin-left: 0px;
	width: 190px;
	height: 61px;
	float: left;
}
#link1{
	background: url(../images/site1.jpg) no-repeat;
}
#link2{
	background: url(../images/site2.jpg) no-repeat;
}
#link3{
	background: url(../images/site3.jpg) no-repeat;
}
</style>
</head>
<body>
<div id="mylinks">
<h1>More Links</h1>
<h2>Some Of My Links</h2>
<div class="link" id="link1"><a href="http://www.mysite2.com/site1.htm">My site</a></div>
<div class="link" id="link2"><a href="http://www.mysite2.com/site2.htm">Link 2</a></div>
<div class="link" id="link3"><a href="http://www.mysite3.com/site3.htm">Link 3</a></div>
</div>
</body>
</html>
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 12-09-2006, 10:09 PM   PM User | #4
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
oops, forgot your styling the link a:

Add this to the CSS
Code:
.link a {
	display:block;
	width:100%; 
	height:100%; 
	font-size: 10px;
}
* html #link a {
	display: inline;
	display: block;
}
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 12-12-2006, 05:50 PM   PM User | #5
dantra
Regular Coder

 
Join Date: Aug 2005
Posts: 132
Thanks: 3
Thanked 0 Times in 0 Posts
dantra is an unknown quantity at this point
Sorry it took me so long to reply but I've been really busy.
I finally got around to trying your example and after tweaking it a bit, it worked like a charm.
Thanks
dantra is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 06:03 PM.


Advertisement
Log in to turn off these ads.