...

View Full Version : Place object X pixels from center



bswb97
07-25-2012, 07:36 PM
I have a fixed object that I'd like to place just outside of my centered layout. I know I can use Left and Right position but with variable screen sizes, this leads to inconsistency. Is there a position command that starts at 50% horizontal (center) and then can be set a certain amount of pixels outside of it?

Maybe I'm making this too complicated, but I was thinking about a Div within a Div -- the first Div is Right: 50%, the second Div is XXX pixels so that it hovers just outside the layout.

tracknut
07-25-2012, 08:11 PM
Typically this is done with a negative left margin:


<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
</head>

<body>
<div style="width:500px;margin:0 auto;border:1px green solid">
<p>centered: sh dflksj hflskjh fsldkjh fslkjf hslkjf hslkjfh slkjfh sldkjf lskf lsjf</p>
<div style="width:200px;margin:0 auto;margin-left:-200px;border:1px red solid">
<p>inside kla dkj lkjh asdlfkjd shlfkjh sldkjfh sldkjf</p>
</div>
</div>
</body>

</html>


Dave

Keleth
07-25-2012, 08:53 PM
bare in mind, this does require knowing the width of the items... if you're trying to position an item but don't know how wide it'll be, you can't do what you're mentioning. Javascript is a way though to allow you to figure out the width of a variable item and center it, if you wanna go that way.

bswb97
07-26-2012, 06:14 AM
The margin trick worked. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum