Solved

How to center an image in an html document

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

910 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

25 Experts available now in Live!

Get 1:1 Help Now