Jump to content

Adding margins to container when centered

Recommended Posts

I have this code for my container

#container { width: 600px; margin: 0 auto; }

So basically I have a centered container on my page which I want to add some margins into it so the text is not right against the borders.I tried with padding but this creates spaces outside the container and I no longer have my width of 600px. If I try margins then the container is no longer centered and is placed depending on the margins I specified. I don't understand why it's not working, I've done it before.Thanks for the help.

Link to post
Share on other sites

Have your tried adding a span's for your text? You can have your container with your styling, but you can also have your text with it's own styling... something like this:html:

<div id="container"><span>Text Here</span></div>


#container { width: 600px; margin: 0 auto; }#container span {padding: 3px;}


Link to post
Share on other sites

So it's not just for one container I'm assuming then. Well, that's really all I can come up with. Perhaps someone else can give you a better suggestion then. :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...