Jump to content

centering div on page help


MDanz

Recommended Posts

can i get the correct code to center this div.  I've tried margin 0  auto, text-align: center etc but it still stays to the left of the page

 

#layer1 {
position: absolute;
visibility: hidden;
width: 400px;
height: 300px;
left: 20px;
top: 300px;

background-color: #000000;
border: 1px solid #FBB917;
padding: 10px;

}

Link to comment
Share on other sites

#layer1 {
position: absolute;
visibility: hidden;
width: 400px;
height: 300px;
   top: 0px;
    left: 50%;
    margin-left: 300px;


background-color: #000000;
border: 1px solid #FBB917;
padding: 10px;

}

 

this works but when i change screen resolution it won't any help??

Link to comment
Share on other sites

Don't use absolute positioning for that - it does exactly what it says, absolutely positions the div container, and does not become fluid on the resolution. Removing them should get rid of the problem (and then changing the top/lefts, as those are absolutes).

 

And using "text-align:center" is best in the body{} tags then using a "text-align:left" in your div to align the text left.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

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.