Solved

How to center an image in an html document

Posted on 2011-03-04
4
327 Views
Last Modified: 2012-05-11
I want to center an image in an HTML document that I am doing.  The only thing to be centered is an image with the dimensions that are 576 pixels wide by 260 pixels tall.  How do I center this image in a blank HTML or ASP.NET page?
0
Comment
Question by:VBBRett
4 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 35041579
This is a very simple way to do it.  There are other ways that may be suitable.  Put the name of your image file in the src="576x260.jpg" part.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Center image</title>
</head>
<body>
<center>
<h1>Center image</h1>
<img alt="576x260" src="576x260.jpg" height="359" width="576" border="1px" />
</center>
</body>
</html>

Open in new window

0
 
LVL 4

Assisted Solution

by:mars-vie
mars-vie earned 250 total points
ID: 35043181
A CSS-version -->

<!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>Unbenanntes Dokument</title>
<style type="text/css">
<!--
#centa {width: 580px; margin: 0 auto; text-align: center;}
-->
</style>
</head>

<body>
<div id="centa">
<h1>Center image</h1>
<img src="01.gif" width="576" height="260" alt="576x260" />
</div>
</body>
</html>
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 35043279
If you know the width of your image, the easiest (and cleanest) way is to add a CSS rule to your image.

@DaveBaldwin: just a quick poin -  <center> is deprecated. Also it's not valid in a STRICT DOCTYPE.

<img src="your)image.jpg" style="width:576px; margin:0px auto; display:block;" />

Open in new window

0
 

Author Closing Comment

by:VBBRett
ID: 35043785
Thank you both for your quick replies!!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now