/    Sign up×
Community /Pin to ProfileBookmark

align divs horizontally

hi css people,

having trouble aligning elements horizontally,

[CODE]<!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-Language” content=”en-us” />
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″ />

<style type=”text/css”>
h1 {
font-family: haettenschweiler;
color: red;
text-align: center;
font-size: 20px;
margin-top: 0;
margin-bottom: 0;
}
body {
background: #000000;
color: #ffffff;
}
a:link {
color: #ffffff;
margin-top: 0px;
}
.watch_image {
margin-top: 10px;
background-color: #FFFFFF;
z-index: 15;
}
img {
border-width: 0px;
background-color: #FFFFFF;

}

a:visited { color: #ffff00;

}

#navigation_2 {
position: relative;
width: 100px;
height: 100px;
z-index: 5;
top: 450px;
left: 0px;
text-align: center;
line-height: 24px;
float: left;
}

.image_div {
border: 7px solid #E80000;
width: 160px;
height: 212px;
z-index: 12;
text-align: center;
background-color: #FFFFFF;
margin-top: 25px;
margin-left: 5px;
margin-bottom: 0px;
margin-right: 5px;
}

.watch_details {
position: absolute; width: 107px;
height: 100px; z-index: 1;
top: -1px;
left: 120px;
}

.description {
font-family: Arial;
font-size: 10pt;
font-weight: bold;
margin-top: 10px;
margin-bottom: 0px;
height: 32px;
}
.price {
font-family: Arial;
font-size: 10pt;
font-weight: bold;
margin-top: 10px;
margin-bottom: 0px;
}

#navigation {

float: left;
width: 110px;
padding: 1px;
z-index: 3;
display: inline;

}

#container {
width: auto;
border: 1px solid red;
z-index: 1;
float: right;
display: inline;

}

#gallery_container_1 {
width: 160px;
height: 327px;
position: relative;

margin: auto;
padding: 1px;
z-index: 7;
text-align: center;
display: inline;

}

#gallery_container_2 {
width: auto;
height: 327px;
z-index: 8;
position: relative;
margin: auto;
padding: 1px;
text-align: center;
display: inline;

}

#gallery_container_3 {
width: 160px;
height: 327px;
position: relative;

margin: auto;
padding: 1px;
z-index: 8;
text-align: center;
display: inline;

}

</style>

<title>Seiko Watches Ladies at Wrist Watch World</title>

</head>

<body >

<!– trying to align everything horizontally using relative positioning –>

<div id=”navigation” >
navigation to be added</div>

<div id=”container”>

<div id=”gallery_container_1″ >
<div class=”image_div” >
<a href=”watches/seiko/SUJ629.htm”>
image 1</a></div>

<p class=”description” ><a href=”watches/seiko/SUJ629.htm”>Seiko
Lady’s<br />
Silver Tone Watch</a></p>
<p class=”price” >SUJ629&nbsp;&nbsp;&nbsp;
$87.50 </p>
</div>

<div id=”gallery_container_2″ >
<div class=”image_div”>
<a href=”watches/seiko/SXG768.htm”>
image 2</a></div>

<p class=”description”><a href=”watches/seiko/SXG768.htm”>Seiko
Lady’s<br />
Gold Tone Watch</a>
</p>
<p class=”price”>SXG768&nbsp;&nbsp;&nbsp;
$95.00
</p>
</div>

<div id=”gallery_container_3″>
<div class=”image_div”>
<a href=”watches/seiko/SXGB70.htm”>
image 3</a></div>

<p class=”description” >
<a href=”watches/seiko/SXGB70.htm” >Seiko
Lady’s<br />
Gold Tone Watch</a>
</p>
<p class=”price”>SXGB70&nbsp;&nbsp;&nbsp;
$88.00
</p>
</div>

</div>

</body>
</html>[/CODE]

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@WebJoelFeb 21.2007 — I removed the "position:relative" because they weren't really doing anything here, changed the width on "gallery_container1" from "auto" (which stretches to right-edge of screen) to "160px" (the same width as gallery-container2 & 3), and added "float:left" to each of them to make them display 'on the same line' (display:inline; wasn't working here for that), and then floated the 'container' itself LEFT instead of RIGHT, so that these would be close to the vertical navigation box, switched to a STRICT !doctype, and added some governance rules in STYLE that will help the page display better overall (imo).

I think that this is how you intended this to look:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html><head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta http-equiv="Content-Style-Type" content="text/css" />

<meta http-equiv="Content-Script-Type" content="text/javascript" />

<title>Seiko Watches Ladies at Wrist Watch World</title>

<style type="text/css">

* {border:0; padding:0; margin:0;}/* Set everything to "zero" */

body {min-height:100%; height:100%;

font:x-small Arial, Verdana, sans-serif;

voice-family: ""}"";voice-family:inherit;

font-size:small;/*for IE 5.5 */

} html>body {font-size:small;}

/*font-size: small; voice-family: ""}"";

voice-family: inherit; font-size: medium;*
/} /* Assist IE rendering height, keyword-font sizes, etc. */

p {font-size: 90%; line-height:1.2em;}

h1, h2, h3, h4, h5, h6 {font-family: 'times new roman', arial, verdana, serif;

font-style:normal; font-variant:normal; font-weight:normal; margin:11px 0 0 10px;}

h1{font-size: 1.93em;}

h2{font-size: 1.72em;}

h3{font-size: 1.52em;}

h4{font-size: 1.42em;}

h5{font-size: 1.32em;}

h6{font-size: 1.21em;}

h1 {font-family: haettenschweiler;color: red;text-align: center;font-size: 20px;

margin-top: 0; margin-bottom: 0;}

body {background: #000000; color: #ffffff;}

a:link {color: #ffffff; margin-top: 0px;}

.watch_image {margin-top: 10px;background-color: #FFFFFF; z-index: 15;}

img { border-width: 0px;background-color: #FFFFFF; }

a:visited { color: #ffff00;}

#navigation_2 {width: 100px; height: 100px; z-index: 5;

top: 450px; left: 0px;text-align: center; line-height: 24px; float: left;}

.image_div {border: 7px solid #E80000;width: 160px;

height: 212px; z-index: 12; text-align: center; background-color: #FFFFFF;

margin-top: 25px;margin-left: 5px; margin-bottom: 0px; margin-right: 5px;}

.watch_details {position: relative; width: 107px;height: 100px; z-index: 1;top: -1px; left: 120px;}

.description {font-family: Arial;font-size: 10pt; font-weight: bold;margin-top: 10px; margin-bottom: 0px;

height: 32px;}

.price {font-family: Arial;font-size: 10pt; font-weight: bold; margin-top: 10px;margin-bottom: 0px;}

#navigation {float: left;width: 110px; padding: 1px; z-index: 3; display: inline;}

#container {width: auto; border: 1px solid red;z-index: 1; float:left; display: inline;}

#gallery_container_1 {width:160px; height:327px;float:left;margin: auto; padding: 1px;

z-index: 7; text-align: center;}

#gallery_container_2 {width:160px; height:327px; z-index: 8;float:left; margin: auto; padding: 1px; text-align: center;}

#gallery_container_3 {width:160px; height:327px; float:left; margin:auto;

padding:1px; z-index:8; text-align: center; }

</style>

<script type="text/javascript"><!--

// -->

</script>

<link rel="shortcut icon" href="favicon.ico"><!-- path to your favicon -->

</head>

<body>

<!-- trying to align everything horizontally using relative positioning -->

<div id="navigation" >

navigation to be added</div>

<div id="container">

<div id="gallery_container_1" >

<div class="image_div" >

<a href="watches/seiko/SUJ629.htm">

image 1</a></div>

<p class="description" ><a href="watches/seiko/SUJ629.htm">Seiko
Lady's<br />
Silver Tone Watch</a></p>
<p class="price" >SUJ629&nbsp;&nbsp;&nbsp;
$87.50 </p>
</div>

<div id="gallery_container_2" >
<div class="image_div">
<a href="watches/seiko/SXG768.htm">
image 2</a></div>

<p class="description"><a href="watches/seiko/SXG768.htm">Seiko
Lady's<br />
Gold Tone Watch</a>
</p>
<p class="price">SXG768&nbsp;&nbsp;&nbsp;
$95.00
</p>

</div>

<div id="gallery_container_3">

<div class="image_div">

<a href="watches/seiko/SXGB70.htm">

image 3</a></div>

<p class="description" >
<a href="watches/seiko/SXGB70.htm" >Seiko
Lady's<br />
Gold Tone Watch</a>
</p>
<p class="price">SXGB70&nbsp;&nbsp;&nbsp;
$88.00
</p>
</div>

</div>


</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@KDLAFeb 21.2007 — You don't need "position: relative." Simply float the right and left columns, applying a margin to the center which will prevent the text (if the div is longer) from wrapping.

KDLA
Copy linkTweet thisAlerts:
@WebJoelFeb 21.2007 — from your posted code:
#gallery_container_2 {

[B][U]width: auto;[/U][/B]

height: 327px;

z-index: 8;

position: relative;

margin: auto;

padding: 1px;

text-align: center;

display: inline;

}[/QUOTE]
this was doing the most damage. :o Put "border:1px solid white" on it and see how it looks. :eek: [U]width:160px[/U] is much better.
×

Success!

Help @changintimes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...