Jump to content
xisto Community
MediYama

Centering A Div without having to center the content in it

Recommended Posts

I'm now rebuilding my website, and I have come against a problem of which I don't know how to fix it. I am using div tags (of course) but what I want to know is how to center the site, without having the text layout centered. Does anyone know how? I have not found any solutions yet. Thanks in advance.MediYama

Share this post


Link to post
Share on other sites

ummm..."nice share" u arent even reading wot ppl write sirat.i have my whole site centered just with center tags.but, everything else is in table inside tables inside tables so it doesnt affect them.but, if u want to center your site like that, u could use margins? the same on both side.

Share this post


Link to post
Share on other sites

Sten, when I use center tags,

 

All the text is also centered like this, which I don't want


I want the site to be centered (the background, the boxes) but the text to just be slammed to the left side.

Share this post


Link to post
Share on other sites

Like i said, marginsit will put it all in the middle if you make the left and right margins the same.

Share this post


Link to post
Share on other sites

just use css to set the left and right margin to auto, and you'll be able to center your div (assuming you also have a width set for the div).

An example would be:

<div id="content" style="width: 745px; margin-left: auto; margin-right: auto;">the content here</div>

So if centering your site, you would put your website inside of that.

Hope this helps, if it doesn't I would recommend posting a link to either your website, or an example of an attempt at what you are doing, so we can take a look at the code, and provide more specific help.

Share this post


Link to post
Share on other sites

I'm now rebuilding my website, and I have come against a problem of which I don't know how to fix it. I am using div tags (of course) but what I want to know is how to center the site, without having the text layout centered. Does anyone know how? I have not found any solutions yet. Thanks in advance.
MediYama

If you want to center horizontally your div or any other block element you can use achieve this with:
<div style="width:10em;margin:0 auto">div content</div>

Best regards,

Share this post


Link to post
Share on other sites

oh yeah, woops, forgot to say!margins dont work too well in other resolutions. i had that problem once when i was making a website for school for an assignment or something.anyway, u fixed it and thats wot counts :P

Share this post


Link to post
Share on other sites

What was mentioned above is the best solution to the problem, but it doesn't work in all browsers - to be more precise, it doesn't work in Internet Explorer. In order to overcome this, you must have a div with text-align: center around the div you want to center. Using only this wouldn't work in Firefox or Opera, but Internet Explorer has no problem with it. However, this would make the text in the main div centered, so you have to use text-align: left in that one :P

Share this post


Link to post
Share on other sites

One thing i REALLY hate is hoe everything works in firefox but not internet explorer.its really annoying, especially on my site, i have about 10 tables inside eachother just to make it work in internet explorer.Firefox actually like knows what people want (well the rendering engine does anyway) but internet explorer... doesnt.

Share this post


Link to post
Share on other sites

One thing i REALLY hate is hoe everything works in firefox but not internet explorer.its really annoying, especially on my site, i have about 10 tables inside eachother just to make it work in internet explorer.
Firefox actually like knows what people want (well the rendering engine does anyway) but internet explorer... doesnt.

It is because internet explorer do not support completely the W3C standards as the others browsers do, as far i know the browser that supports almost completely the standards is Opera following by the Gecko browsers like Firefox.

Best regards,

Share this post


Link to post
Share on other sites

It is (almost) always possible to create such code that will behave the same in both Internet Explorer and Firefox. What's more, when these two display the same thing, you can count on Opera doing so, too. When I am coding a HTML/CSS template, I use Firefox for preview, only. When I am completely satisfied with the outcome, I turn to tweaking the code for other browsers. For beginners, this will probably be a useless method, but once you learn how Internet Explorer deals with different code, you will start avoiding automatically, which will leave little to be altered when you fire up Internet Explorer :P

Share this post


Link to post
Share on other sites

My brother uses Opera on his tv.some things dont work on it. the main problem i found is that with multiple iframes on the site, even if you use names and target a link to a particular iframe, it will just show it in the first iframe on the site.thats wot i hate about opera.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.