Jump to content

new to css


dadamssg

Recommended Posts

im just now diving into css and i want to create a div thats a fixed width and heighth and thats centered in the browser. how do i go about centering the div? i know i can center the whole <body> tag but that centers everything within the div as well. ive been playing around with it for a while but can't seem to get anywhere. i just want all the content of my page in this div. any help?

 

Link to comment
https://forums.phpfreaks.com/topic/142564-new-to-css/
Share on other sites

Hello,

 

  The last commenter is correct.  However, some browsers may not show this properly unless you are specifying display:block;.  So, as an example:

 

<style type="text/css">
  #object {
    height:  100px;
    width:    650px;
    display:  block;
    margin:  0 auto 0 auto;
    /* To ensure that you have proper padding still */
    padding: 2px 4px 2px 4px;
    /* Just for visibility */
    background-color: black;
    color:white;
    border: red dashed 2px;
   }
</style>
<div id="object">
X X X X X X X 
</div>

 

I put this up here.

 

Let me know if you have any questions!

Link to comment
https://forums.phpfreaks.com/topic/142564-new-to-css/#findComment-749464
Share on other sites

If I recall correctly, I was having issues getting cross-browsers with IE6 and 7 vs Firefox, safari, etc..  Most everything worked for firefox and safari but odd issues arose with iex.  The issue was without saying to display:block, then the elements inside of the div became mis-aligned vs with it.  I has just started to do this out of habit at this point.

 

As far as the height and width,  I specified them just as an example so the div didn't take up the whole page.

Link to comment
https://forums.phpfreaks.com/topic/142564-new-to-css/#findComment-749731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.