niche Posted October 5, 2010 Share Posted October 5, 2010 What do I need to add/change to this style to center it AND have display a margin? <div style="display:block;margin:0 auto;width:90px;"> <input type="submit" value="Add to Cart" /> </div> Link to comment Share on other sites More sharing options...
justinbriggs1 Posted October 5, 2010 Share Posted October 5, 2010 A little confused, so you want a margin on an element that is centered with auto left and right margins? Link to comment Share on other sites More sharing options...
niche Posted October 5, 2010 Author Share Posted October 5, 2010 Yes. Link to comment Share on other sites More sharing options...
ShadowMage Posted October 5, 2010 Share Posted October 5, 2010 You want margins on top/bottom or on left/right? If top and bottom just change the 0 (ie, margin: 4px auto;)If you want them on the sides, try applying left and right margins to the input itself. You might also need to put text-align: center on the div. Are you trying to create a liquid layout where the elements will not get any closer to each other if the browser window gets too small? Link to comment Share on other sites More sharing options...
justinbriggs1 Posted October 5, 2010 Share Posted October 5, 2010 And, if you are just looking to position it left or right from center, try this:element.style {display:block;left:20px;margin:0 auto;position:relative;width:90px;} Link to comment Share on other sites More sharing options...
niche Posted October 5, 2010 Author Share Posted October 5, 2010 Tried margin: 5 auto; instead of margin: 5px auto;. The correct format makes all the difference. I'm also very thankful for help looking at the same problem in different ways.Thanks to jwburnside and ShadowMage for their top-notch help.Niche Link to comment Share on other sites More sharing options...
ShadowMage Posted October 5, 2010 Share Posted October 5, 2010 Tried margin: 5 auto; instead of margin: 5px auto;. The correct format makes all the difference.It's a good idea to always include a unit when defining widths and such. That's why I usually write margin: 0px auto; instead of just margin: 0 auto; like I see most people here do. Link to comment Share on other sites More sharing options...
niche Posted October 5, 2010 Author Share Posted October 5, 2010 Point. That's just another reminder of justsomeguys quote, "[know] why it works". I know now that the unit's need for it to work.Thanks Again, Niche Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.