Shoutbox

CSS Help! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: General (/forumdisplay.php?fid=11)
+---- Forum: General Chit Chat (/forumdisplay.php?fid=14)
+----- Thread: CSS Help! (/showthread.php?tid=75203)

CSS Help! by Eddie on 06-09-2007 at 09:50 AM

Ok then, after talking with Nathan a bit i decided to move into a DIV / CSS Based layout instead of tables everywhere, and its been going pretty well and the code looks better to me but i'm not sure...

i have hit a small problem, i am wanting to get the 'container' in the exact middle of the page no matter what resolution, how would i do this? [code is below], btw im only making this for IE6/7 and Firefox based users for now :)

code:
#maincontainer {
    left: 30%;
    top: 200px;
    width: 400px;
    height: auto;
    margin: 0 auto;
    vertical-align: middle;
    padding: 5px;
    position: absolute;
    background-color: #FFFFFF;
    -moz-opacity: 0.65;
    filter: alpha(opacity=65);
}
The website can be found here, any other comments would be appreciated, but be aware its only a temporary page :P
RE: CSS Help! by ayjay on 06-09-2007 at 10:12 AM

add margin-left: -200px; (half of the div width) and left: 50%; to the div properties. That way, you're making it 50% from the left of the page to the middle of the div.


EDIT: You'll probably wanna use this too to make sure it acts properly :P...

code:
div {
-moz-box-sizing: border-box;
box-sizing: border-box;
}

RE: CSS Help! by Eddie on 06-09-2007 at 11:34 AM

Sorry you misunderstood i think, thats the css code of the box, i want that box centred on the page, not content inside of that centred directly, i also want it completely centered on the page from the top and the side.

Also...Is it possible that the height be specified by how much writing there is?? *-)


RE: CSS Help! by Nathan on 06-09-2007 at 12:01 PM

just get rid of the height atribute.


RE: CSS Help! by Supersonicdarky on 06-09-2007 at 12:25 PM

cant you do margin: auto; for ff and text-align: center; in parent for ie?

i'm not sure if auto margin works for vertical align

also you will need to have set height and width


RE: CSS Help! by Nathan on 06-09-2007 at 12:30 PM

no it doesnt, i asked him to try that too. And its not margin: auto, its margin: 0 auto;  ;)


RE: CSS Help! by hmaster on 06-09-2007 at 12:32 PM

Try this: http://exanimo.com/examples/css/vertical-centerin...-floated-shim.html

Source: http://exanimo.com/css/vertical-centering-with-a-floated-shim/


RE: CSS Help! by Lou on 06-09-2007 at 12:33 PM

for the vertical alignment:

code:
div {
vertical-align:middle;
}

RE: CSS Help! by Nathan on 06-09-2007 at 12:39 PM

Here's an example I just coded up: You should be able to learn from it ;)

http://skoolfun.com/center.htm

Hope it helps :)


RE: CSS Help! by ayjay on 06-09-2007 at 12:45 PM

quote:
Originally posted by Eddie
Sorry you misunderstood i think, thats the css code of the box, i want that box centred on the page, not content inside of that centred directly
That's exactly what it does. To do it centered from the top, just do the same but with margin-top and top:50%.

EDIT: oh, just seen it's not a specified height, nvm :P


quote:
Originally posted by Napbree
Here's an example I just coded up: You should be able to learn from it ;)

http://skoolfun.com/center.htm

Hope it helps :)
Doesn't work in IE.
RE: CSS Help! by Eddie on 06-09-2007 at 12:49 PM

quote:
Originally posted by Napbree
Here's an example I just coded up: You should be able to learn from it ;)

http://skoolfun.com/center.htm

Hope it helps :)
Cool, but box to big and i dont understand how you did that because you just told me to delete the height attribute!
quote:
Originally posted by hmaster
Try this: http://exanimo.com/examples/css/vertical-centerin...-floated-shim.html

Source: http://exanimo.com/css/vertical-centering-with-a-floated-shim/
i could of done a search but i decided to ask here because its easier and i get multiple opinions.
quote:
Originally posted by .Lou
for the vertical alignment:
code:
div {
vertical-align:middle;
}

will try that thanks.

i will edit once tried these. thanks.
RE: CSS Help! by albert on 06-09-2007 at 02:56 PM

The easy way to do this?

Simply put everything you want aligned in an another div, and on the html page write.

code:
<div align='center>
     <div class='container>
     </div>
</div>


Saves you from a bunch of problems to center-it horizontally. As for the vertical, depending on how big your container is (e.g. 40%), you would simply have to do : (100% - 40%) /  2, and then use the result ( 30% here) and use it as top in your position propriety.

code:
#container
{
position:relative;
top:30%;
}


RE: CSS Help! by ayjay on 06-09-2007 at 03:17 PM

quote:
Originally posted by alby
As for the vertical, depending on how big your container is (e.g. 40%), you would simply have to do : (100% - 40%) /  2, and then use the result ( 30% here) and use it as top in your position propriety.

That's fine if you have a fixed size, which he doesn't :P
RE: CSS Help! by Lou on 06-09-2007 at 04:10 PM

quote:
Originally posted by alby
code:
<div align='center>
     <div class='container>
     </div>
</div>

First of all, that's incorrect. Also, it's not xhtml valid.
code:
<div style="align:center;">
<div class="container">
stuff here
</div>
</div>

RE: CSS Help! by Eddie on 06-09-2007 at 04:23 PM

quote:
Originally posted by .Lou
quote:
Originally posted by alby
code:
<div align='center>
     <div class='container>
     </div>
</div>

First of all, that's incorrect. Also, it's not xhtml valid.
code:
<div style="align:center;">
<div class="container">
stuff here
</div>
</div>

Cheers, will try that tomorrow :)
RE: CSS Help! by Eddie on 06-11-2007 at 12:47 PM

i had a fiddle with these different methods, none of which worked *-)