Member Avatar for P0lT10n

Hello, I'm trying to do a margin-left depending on the resolution of the screen...
I want to margin the page to hold it in the center all... like daniweb... you can see that all is centered, but then you can move things to the left and right like logo and adds... I think that I could do this with a div, and then put all inside and put it centre and it will be centre depending on resolution, am I right ???

Recommended Answers

All 5 Replies

Maybe I misunderstood you, but this is very common:

display: block;
margin-left: auto;
margin-right: auto;
/*OR...0*/
margin-left: 0 auto;
margin-right:  0auto;

I'm not sure which is correct, but it's something like that.

Member Avatar for P0lT10n

It dosen't work... thanks anyway !

If you're talking about the width, you could say

<style>
    body{margin: 0px, 5%, 0px, 5%;}
</style>

... is that what you're talking about?

To center a page, first it must have the entire content inside the outermost div, which must have a width applied in the css. Then you add margin:auto to that div's css and that's it done.
eg assuming like most people your outermost div has the id = "wrapper" (it's just traditional to call it wrapper, it doesn't matter what it's called)

#wrapper{
width:960px; /* or whatever you're using, but not the size of your own personal screen! */
margin:auto;
rest of your css styles for wrapper follow.

}

PS as for saying display:block - divs ARE block automatically...

Member Avatar for P0lT10n

To center a page, first it must have the entire content inside the outermost div, which must have a width applied in the css. Then you add margin:auto to that div's css and that's it done.
eg assuming like most people your outermost div has the id = "wrapper" (it's just traditional to call it wrapper, it doesn't matter what it's called)

#wrapper{
width:960px; /* or whatever you're using, but not the size of your own personal screen! */
margin:auto;
rest of your css styles for wrapper follow.

}

PS as for saying display:block - divs ARE block automatically...

Thanks ! It works !!!! I had had my width: auto; and margin: auto; and all the time, all to the left and now I understand why, thanks again, and should I use bigger width for bigger screens ???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.