Jump to content

Middle Align a DIV


legohalflife2man

Recommended Posts

I have a DIV that I would like centered in the exact middle of the page. I have it centered horizontally, but now I need to center it vertically, as well. Here is my CSS for the entire page:

 

body {
background: #000000;
margin: auto;
}
.splash {
background: url("/images/coming_soon.jpg") 0 0 no-repeat;
width: 910px;
height: 361px;
margin: auto;
}

 

The page only contains this DIV that I want to center. How could I accomplish the vertical alignment of this DIV? Thank you in advance for your help.

Link to comment
Share on other sites

Hi Lego, I had to tested out your scenerio with one of my images on my pc the way you wanted it. Do ou know how to do a floating div tag? Because that is how is what I use to have what you want. I will place the code here and give it a try. It worked for me

 

<style type="text/css">
<!--
body {
background: #000000;
margin: auto;
}
#splash {
position:absolute;
left:359px;
top:255px;
width:910px;
height:361px;
z-index:1;
margin:auto;
background:url(file:///C|/wamp/www/Hair_Business_Website/WeftHair/HairColorChart.jpg);
}
-->
</style></head>

<body>
<div id="splash"></div>
</body>
</html>

 

I did not make a style sheet for it. I pretty much did it on one page to test it, but you can copy and paste the style code onto your style sheet buy copying and pasting the codes between the arrows.

Link to comment
Share on other sites

The above won't actually center the image properly. If you were to resize the wondow it would stay in the same position, not snap to the center.

Unfortunately this is the one thing I've never been able to work out how to do. The only way would be to create a table (using display: table; display: table-row; etc. Not the actual html <table>) of three columns and three rows and place what you want centered in the middle one.

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.