Forum Moderators: open
I set column 1 and column 3 to have a background colour of blue, what I want to end up with is the image in the middle and the blue backgroun flowing out to either side.
When I view it the image is in the center but there is about a 5 millimetre gap on the left and right where the background colour should run to the end.
How can I fix it?
Thanks
I'd suggest you don't use a table :) It's pretty easy to do using CSS and basic HTML, for example:
HTML:
<div class="picture"><img src="my_image.png" alt="My image" /></div> CSS:
div.picture {
background-color: blue;
}div.picture img {
display: block;
margin: 0 auto;
}
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#03a5ff"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
<td width="832"><img src="images/AP-Diagnostics_07.gif" alt="" height="47" width="832" border="0" /></td>
<td bgcolor="#03a5ff"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
</tr>
</table>
</body>
Is it correct?
Thanks
HTML:
<body>
<div class="picture"><img src="images/AP-Diagnostics_07.gif" alt="" height="47" width="832" /></div>
</body> CSS:
div.picture { background-color: #03a5ff; }
div.picture img { display: block; margin: 0 auto; } A <div> (or any block level element) automatically fills up the full width it can, and the image will sit on top of its background colour. The image is made display:block to get around gaps for descenders caused by line-height, and centred using margin: 0 auto.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Unique title here</title>
<style type="text/css">
body,html { margin:0; padding:0; }
.color-side-col { background-color: #03a5ff; }
#center-col { width:832; }
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="color-side-col"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
<td id="center-col"><img src="images/AP-Diagnostics_07.gif" alt="" height="47" width="832" border="0" /></td>
<td class="color-side-col"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
</tr>
</table>
</body>
</html>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="color-side-col"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
<td id="center-col"><img src="images/AP-Diagnostics_07.gif" alt="" height="47" width="832" border="0" /></td>
<td class="color-side-col"><img src="images/spacer.gif" alt="" height="32" width="32" border="0" /></td>
</tr>
</table>