sseeley Posted August 30, 2009 Share Posted August 30, 2009 Can anyone help me? I am trying to place an object 50px left of center. This will help me cope with the varying screen sizes. Can any one help me with this code. I am hoping to use a div? Many thanks in advance Stuart Link to comment https://forums.phpfreaks.com/topic/172479-css-center/ Share on other sites More sharing options...
peranha Posted August 30, 2009 Share Posted August 30, 2009 #left { margin-left: -50px; } Something like that will work. Link to comment https://forums.phpfreaks.com/topic/172479-css-center/#findComment-909300 Share on other sites More sharing options...
haku Posted August 31, 2009 Share Posted August 31, 2009 It's not the easiest thing to do. You probably have to trick the system into it like this: <div id="container"> <div id="item_to_be_offcenter">div contents</div> </div> Then you can set the CSS like this: #container { width: 300px; margin: 0 auto; } #item_to_be_offcenter { margin-left: -50px; } This code creates a container that is centered, holding the items that are to be off center by 50 px. A negative left margin is then used to move the contents to 50 px off the center. Link to comment https://forums.phpfreaks.com/topic/172479-css-center/#findComment-909504 Share on other sites More sharing options...
TheFilmGod Posted August 31, 2009 Share Posted August 31, 2009 If the div you are centering will be going into a parent div that has a fixed width and the width will not be changing - you could just calculate the margin-left and apply a margin-left to trick the system. Only 1 div needed. Link to comment https://forums.phpfreaks.com/topic/172479-css-center/#findComment-909720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.