Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 7
There are 1 users currently browsing forums.
HTML/CSS Coding The basis of the World Wide Web, HTML, XHTML, and CSS make our forum possible, so it must be important right? Ask questions and receive help with these markups here.

Reply
  #1  
Old 08-06-2009
Just a "Little" Kid
 
Join Date: Jul 2005
Location: Shetland
Age: 20
Posts: 92
Rep Power: 6
omen is on a distinguished road
Why wont the image center?

I have two image and I want the "h1" image to center

even tho I have written in "background-position:center;" it will wont work

style.css
Code:
@charset "UTF-8";
/* CSS Document */	
body { background-color:#000;
	background-image:url(images/JeffreeStarBG.png);	
	background-repeat:no-repeat;
	background-position: top center;
	padding-top:100px;
	background-attachment:fixed;
}

h1 { z-index: 3;
	position:absolute;
	top:350px;
	width:480px;
	height:80px;
	margin:0;
	padding:0;
	background-image:url(images/logo.png);
	background-position:center;
	text-indent:-9999px;
}
index.html
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link href="style.css" media="all" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Website Title</title>

</head>
<body>
<h1>Logo Here</h1>
<h2>Welcome</h2>


</body>
</html>

Last edited by omen; 08-06-2009 at 10:52 PM. Reason: didnt include style.cc
Reply With Quote
  #2  
Old 08-07-2009
Stephen Bryant's Avatar
I eat trolls.
 
Join Date: Aug 2006
Location: North Carolina
Age: 21
Posts: 1,216
Rep Power: 6
Stephen Bryant is on a distinguished road
Re: Why wont the image center?

Wouldn't this just center the image within the h1 tag? I don't have your images, but it seems to me that's what it would do.
Reply With Quote
  #3  
Old 09-08-2009
Stealther's Avatar
Stuck in the Code....
 
Join Date: Sep 2009
Location: In the code in the US
Age: 15
Posts: 82
Rep Power: 2
Stealther is on a distinguished road
Re: Why wont the image center?

Have you tried to put a <center> </center> tag around the <h1></h1> tags? I have my logo in the center and I just place the image inside <center></center> tags and that seems to help out....try that
Reply With Quote
  #4  
Old 09-09-2009
Goodbye Youngcoders
 
Join Date: Dec 2005
Posts: 1,861
Rep Power: 6
Umang is on a distinguished road
Re: Why wont the image center?

Avoid using <center> tags. They are deprecated.

<center> tags are deprecated. Try using relative positioning instead of absolute positioning. Then you should also remember that when you say background-center, you are centering the BG in the h1. If the h1 itself is not centered with respect to the page, then the BG won't be centered w.r.t the page.
Try making positioning relative and then change "margin" from "0" to "0 auto". (zero space 'auto'). Here's the first result from Google about auto margins: CSS Centering: Auto-width Margins
Reply With Quote
  #5  
Old 09-09-2009
Stealther's Avatar
Stuck in the Code....
 
Join Date: Sep 2009
Location: In the code in the US
Age: 15
Posts: 82
Rep Power: 2
Stealther is on a distinguished road
Re: Why wont the image center?

Quote:
Avoid using <center> tags. They are deprecated.

<center> tags are deprecated. Try using relative positioning instead of absolute positioning. Then you should also remember that when you say background-center, you are centering the BG in the h1. If the h1 itself is not centered with respect to the page, then the BG won't be centered w.r.t the page.
Try making positioning relative and then change "margin" from "0" to "0 auto". (zero space 'auto'). Here's the first result from Google about auto margins: CSS Centering: Auto-width Margins

Oh thanks Umang, I didn't know that those tags were deprecated....but it still works on my site!
Reply With Quote
  #6  
Old 09-10-2009
Goodbye Youngcoders
 
Join Date: Dec 2005
Posts: 1,861
Rep Power: 6
Umang is on a distinguished road
Re: Why wont the image center?

It is deprecated by the W3C, which means that by the HTML (or XHTML) standards, the usage of <center> tags should be avoided. Pages using center tags will not be considered as valid by the W3C validator.

Alignment, font styles, and horizontal rules in HTML documents

However, browsers will still center everything inside a <center> tag, to support old websites. Old versions of IE may be pretty fussy, and will require workarounds to get something to center without <center> tags.

Reading a little from the net will help you understand how to center something with CSS. When to use the text-align property and when to use the margin. property.
__________________
I'm off to sigcont.com
Reply With Quote
  #7  
Old 09-21-2009
Child
 
Join Date: Feb 2008
Posts: 92
Rep Power: 3
phasex is on a distinguished road
Re: Why wont the image center?

There is a way around this. create an inline style for the header (h1) tag.

<h1 style="text-align:center; margin-left:auto; margin-right:auto">....</h1>

text-align is used to accommodate for IE users.
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nasty Looking Image RyanT .Net Programming 0 02-29-2008 03:05 PM
Center the image asgsoft HTML/CSS Coding 4 12-27-2006 08:35 AM
Image into subimages StarIsFar Java Programming 5 04-09-2006 04:05 PM
Checking source codes of image, audio and video files onauc C and C++ Programming 7 06-22-2005 12:18 AM
How to Link a Image Helloadam HTML & CSS Articles 2 09-08-2004 03:44 PM