Possible Duplicate:
How to align a <div> to the middle of the page
I need is to show the content of a web page in the middle of the screen, no matter what screen size it is, big or small, resolution high or low, it always gets automatically adjusted to the middle of screen.
You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.
HTML <center> Tag.
text-align: center; on the h1 element and it will automatically center align the h1. text-align: center; aligns only the content(text) of the h1 element to the center, not the h1 element itself.
Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.
I'm guessing you want to center the box both vertically and horizontally, regardless of browser window size. Since you have a fixed width and height for the box, this should work:
Markup:
<div></div>
CSS:
div { height: 200px; width: 400px; background: black; position: fixed; top: 50%; left: 50%; margin-top: -100px; margin-left: -200px; }
The div should remain in the center of the screen even if you resize the browser. Just replace the margin-top and margin-left with half of the height and width of your table.
Edit: Credit goes to CSS-Tricks, where I got the original idea.
Solution for the code you posted:
.center{ position:absolute; width:780px; height:650px; left:50%; top:50%; margin-left:-390px; margin-top:-325px; } <table class="center" width="780" border="0" align="center" cellspacing="2" bordercolor="#000000" bgcolor="#FFCC66"> <tr> <td> <table width="100%" border="0"> <tr> <td> <table width="100%" border="0"> <tr> <td width="150"><img src="images/banners/BAX Company.jpg" width="149" height="130" /></td> <td width="150"><img src="images/banners/BAX Location.jpg" width="149" height="130" /></td> <td width="300"><img src="images/banners/Closet.jpg" width="300" height="130" /></td> <td width="150"><img src="images/banners/BAX Company.jpg" width="149" height="130" /></td> <td width="150"><img src="images/banners/BAX Location.jpg" width="149" height="130" /></td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0"> <tr> <td width="150"><img src="images/banners/BAX Company.jpg" width="149" height="130" /></td> <td width="150"><img src="images/banners/BAX Location.jpg" width="149" height="130" /></td> <td width="300"><img src="images/banners/Closet.jpg" width="300" height="130" /></td> <td width="150"><img src="images/banners/BAX Company.jpg" width="149" height="130" /></td> <td width="150"><img src="images/banners/BAX Location.jpg" width="149" height="130" /></td> </tr> </table> </td> </tr> </table>
--
How this works?
Example: http://jsfiddle.net/953Yj/
<div class="center"> Lorem ipsum </div> .center{ position:absolute; height: X px; width: Y px; left:50%; top:50%; margin-top:- X/2 px; margin-left:- Y/2 px; }
To position the div
vertically and horizontally, divide X and Y by 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With