Solved

How to center an image in an html document

Posted on 2011-03-04
4
330 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 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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

695 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