Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2013, 10:22 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,526
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
2 Simple Header images not centering ??

Hi,

Some very basic html code.

Should give me centered images, but I must have got it
wrong somewhere

My html:
PHP Code:
<html>
<
head>
<
style type="text/css" media="all">
* {
    
margin0;
    
padding0;
    }

#mainC {
    
width:100%;
    
margin:0px auto;
    }

#mainL {
    
width:100%;
    
float:left
    }
    
#mainR {
    
width:100%;
    
float:right
    }
    
#banner {
    
displaynone;
    
positionrelative;
    
top0px;
    
left0px;
    
border3px solid black;
    
overflowhidden;
}

#imgContainer {
    
positionabsolute;
    
top0px;
    
left0px;
}

#imgContainer img{
    
margin0px 0px 0px 0px;
    
padding0px 0px 0px 0px;
    
displayinline;
}
    
    
img 
    
bordernone
    }

h1{
     
color:#4B4B4B;
    
}

h2{
     
font-size:32px;
    
text-align:center;    
    
font-weightbold;
    
color:#773500;
    
}    
</
style>    
</
head>
<
body>
<
div id="bk_image">    </div>
    
<
div id="mainC">
    
    <
div style="margin:10px 0 0 100px ; "
    <
span style="font:Helvetica,Arial,sans-serif; font-size:20px; color:#000000;">Auto World</span>
    <
span style="font:Helvetica,Arial,sans-serif; font-size:16px; color:#000000;">The Maddest Auto Community</span>
    <
br><br>
    </
div>
    <
img alt="Auto World" title "Auto World" src="/images/trees.jpg" >
    <
div style "margin: 0 auto;">
    <
div id="banner">
    <
div id="imgContainer"></div>
    </
div// end banner div
    
</div>  // end center div
    
<br><br>
</
div>
</
div>
</
body>
</
html
The live page is here:

http://professional-world.com/

Any one see the problem ??


Thanks




.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-23-2013, 01:34 PM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
niralsoni is an unknown quantity at this point
Enclose your piece of code in a <center> tag as shown below -
Code:
<center>
    <img alt="Auto World" title = "Auto World" src="/images/trees.jpg" > 
    <div style = "margin: 0 auto;"> 
    <div id="banner"> 
    <div id="imgContainer"></div> 
    </div> // end banner div 
    </div>  // end center div
</center> 
niralsoni is offline   Reply With Quote
Old 01-23-2013, 01:58 PM   PM User | #3
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,049
Thanks: 9
Thanked 82 Times in 82 Posts
jerry62704 is on a distinguished road
Since you have a fixed width (1800) you could put in a fixed padding of 1800 - 900 / 2 or 450. But if the screen is less than the 1800 then the image will not appear centered.

If you wanted to do it more that css way then add margin-left: auto; and margin-right: auto; to the image container. This also has the problem that it won't appear centered if the screen is less than 1800 wide.
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 01-23-2013, 03:21 PM   PM User | #4
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Try this:

Code:
<div id="container" style="width: 960px;margin: 0 auto;">
<div id="bk_image"></div><div id="mainC">
	
	<div style="margin:10px 0 0 100px ; "> 
	<span style="font:Helvetica,Arial,sans-serif; font-size:20px; color:#000000;">Auto World</span>
	<span style="font:Helvetica,Arial,sans-serif; font-size:16px; color:#000000;">The Maddest Auto Community</span>
	<br><br>
	</div>
	<img alt="Auto World" title="Auto World" src="/images/trees.jpg">
	<div style="margin: 0 auto;">
	<div id="banner" style="height: 150px; width: 900px; display: block;">
	<div id="imgContainer" style="width: 1800px; left: 0px;"><img id="img_1" src="http://expert-world.org/banners/top-ten-fitness-diets.jpg"><img id="img_2" src="http://expert-world.org/banners/family-fitness-activities.jpg"></div>
	</div> // end banner div
	</div>  // end center div
	<br><br>
</div>

</div>
tempz is offline   Reply With Quote
Old 01-23-2013, 04:24 PM   PM User | #5
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello jeddi,
Do not use deprecated <center> tags!

To center an element you need three things:
  1. a valid DocType
  2. an element with a width
  3. that elements right/left margins set to auto

Since your #banner gets it's 900px width from inline styling, adding this bit in red to your CSS will center it.
Code:
#banner {
    border: 3px solid black;
    display: none;
    /*top: 0;
    left: 0; */
    margin: auto;
    overflow: hidden;
    position: relative;
}
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 01-23-2013, 09:23 PM   PM User | #6
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,526
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Thanks for all the replies.

I don't understand this comment:

Quote:
Since you have a fixed width (1800)

I have declared width:100%;

I don't think I have any 1800 statement ???


I thought this would center everything inside it. ??

Code:
#mainC { 
    width:100%; 
    margin:0px auto; 
    }
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-23-2013, 09:58 PM   PM User | #7
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,049
Thanks: 9
Thanked 82 Times in 82 Posts
jerry62704 is on a distinguished road
Quote:
Originally Posted by jeddi View Post
Thanks for all the replies.

I don't understand this comment:




I have declared width:100%;

I don't think I have any 1800 statement ???


I thought this would center everything inside it. ??

Code:
#mainC { 
    width:100%; 
    margin:0px auto; 
    }
When I looked at it in Firebug and the element.style width.

You override the mainC margin. Look at "banner" in firebug and you will see the margin becomes "0".
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 01-23-2013, 11:13 PM   PM User | #8
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Quote:
Originally Posted by jeddi View Post

I thought this would center everything inside it. ??

Code:
#mainC { 
    width:100%; 
    margin:0px auto; 
    }
No, not quite. In that bit of CSS the margin: 0 auto; only affects the outside of #mainC, not the contents. It can't center #mainC because, at 100% width, there is nothing to center.
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 01-24-2013, 06:37 AM   PM User | #9
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,526
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
OK - thanks for your patience.

I really should know this stuff by now !!

Anyway, so the answer is,
If I want to center my page - I NEED to give it a width ?

So If I choose, say 1200px.
For 90 % of monitors, I guess that will be OK ?


EDIT: Well, just tried that on mine and the image was not centered
but over to the LEFT hand side.

I changed the width to 1000px and now, on my monitor, it looks centered.

Don't know about others though


.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.

Last edited by jeddi; 01-24-2013 at 06:43 AM..
jeddi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

Forum Jump


All times are GMT +1. The time now is 12:14 AM.


Advertisement
Log in to turn off these ads.