Jump to content

HTML - Center a DIV Box


Gamerz

Recommended Posts

So I need help centering a DIV box...how would I do this?

 

Here is the box...feel free to try it:

<div style="border:1px  solid; width:650px; height:200px; overflow:auto;">
<div class="image">
  <a href="lol.php"> <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
  <p>ECL Fall '09</p></a>
</div>
<div class="image">
   <a href="lol.php"> <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
  <p>Geophysical Science</p></a>
</div>
<div class="image">
  <a href="lol.php">  <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
  <p>Math</p></a>
</div>
</div>

Link to comment
https://forums.phpfreaks.com/topic/186779-html-center-a-div-box/
Share on other sites

Set "margin: 0 auto;" in the CSS (I think it's that way around anyway, if that doesn't work try it the otherway round, I always forget what order the parameters are in, I don't use CSS enough for it to stick in my mind).

 

Are you a programmer or do you use tables?

I'm more back end than design. I'm guilty of sometimes using tables for layout, but generally only for forms. For some reason I can just never remember what order the properties go for border, margin etc. in CSS. Probably because I use them so infrequently.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>

<style type="text/css">

	body {
		text-align: center;
	}

	#page-wrap {
		margin: 0 auto;
		border:1px  solid; 
		width:650px; 
		height:200px; 
		overflow:auto; 
		text-align: left;
	}

</style>

</head>

<body id="homepage">

<div id="page-wrap">

	<div class="image">
		<a href="lol.php"> <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
		<p>ECL Fall '09</p></a>
	</div>

	<div class="image">
		<a href="lol.php"> <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
		<p>Geophysical Science</p></a>
	</div>

	<div class="image">
		<a href="lol.php">  <img src="folder_icon.jpg" alt="image" class="gradualfader"  style="border: 0px dashed black;" width="50" height="50"/>
		<p>Math</p></a>
	</div>

</div>


</body>
</html>

 

These code will make your div centered.

 

 

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.