February 9th, 2013, 12:25 AM
Left % - px ??
I want to keep my div in the center of the page so I used
but that keeps the left side at 50% rather than the corner, so I was thinking of subtracting half the div which is 300px to make it centered. so like
left: 50% - 150px
but that doesnt work. So any ideas how to make this work or a better way to do it.
EDIT: Ah nevermind I figured it out, I had somehow embedded a position: absolute in my html file which was screwing everything off. Thanks for the help.
February 9th, 2013, 12:44 AM
there is no subtraction (or any other calculation) in CSS. Not sure where you got this from.
Block elements are centered by setting the left and the right margin to "auto", as a Google search would have told you.
February 9th, 2013, 01:04 AM
I know very well how to use google, I set the left and right margin to "auto" and they did not work either. Also I know that css does not do calculation I was simply showing you my logic so you could understand what I was trying to accomplish.
Originally Posted by Jacques1
EDIT: Nevermind I found out there was a position: absolute hiding in my html file that was messing up everything. Thanks for the help.
February 9th, 2013, 01:27 AM
Well, that would have been important info.
Originally Posted by harrjm
The problem is that many people actually do not know how to Google (or they're simply too lazy). So when you ask a very general question like "How do I center a div element?", you're likely to get a RTFM.
But when you ask a specific question with concrete info, it's much easier and more appealing to give a specific answer. I mean a problem description like this: "I tried centering a div with margin: auto, but it's still aligned to the left. Here's the full CSS: ..., Here's a screenshot: ..."
Remember that we don't know what you know or see what you see. So it all comes down to your problem description.
Just a suggestion ...