Solved

How to center an image in an html document

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

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 42

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now