?
Solved

How to center an image in an html document

Posted on 2011-03-04
4
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1000 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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