[SOLVED] Problems with centering in CSS.

This is a discussion on "[SOLVED] Problems with centering in CSS." within the Web Page Design section. This forum, and the thread "[SOLVED] Problems with centering in CSS. are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 30th, 2007, 02:56
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Problems with centering in CSS.

Okay, I have tried everything people. lol... It's starting to get agrivating, lol...

For css I have tried,
HTML: Select all
img {
 border: none;
 align: middle;
}
HTML: Select all
img.displayed {
 display: block;
 margin-left: auto;
 margin-right: auto;
}
HTML: Select all
#centeredimage { 
position: relative; 
left: 50%; 
margin-left: -50%;
}
So finally I tried

HTML: Select all
 <center>
  <img src="images/rules/Jesus01.gif" alt="Rules Bottom logo"
  width="180" height="179">
  </center>
And that worked but it's depreciated....

Any help?
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote

  #2 (permalink)  
Old Oct 30th, 2007, 03:22
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

Can't help you since you did not include your HTML code, and you did not specify your question clearly..

Try posting the complete file (HTML, CSS, whatsoever..) and you will get a much more quick response..

P/S: Do you know the magic word margin: 0 auto;?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #3 (permalink)  
Old Oct 30th, 2007, 03:47
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

The one with <center></center> is my html code for it. i tried it with the css version but them used the <center> tags as that's the only thing that worked. And no I'm not sure what u mean my the magic word...
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #4 (permalink)  
Old Oct 30th, 2007, 03:55
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

All you need to si is to put your image inside a div and set the div margin reffer to the magic word

Something like this:

HTML: Select all
#image {
margin 0 auto; /*center your image horizontally*/
width: auto; /*depends on your image size*/
height: auto; /*depends on your image size*/
}
HTML: Select all
<div id="image">
<img src="http://www.webforumz.com/images/rules/Jesus01.gif" alt="Rules Bottom logo"  width="180" height="179">
</div>
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #5 (permalink)  
Old Oct 30th, 2007, 05:38
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

it's weird. that do'nt even work.
here's the page it's on.l http://newbreedjesusfreaks.com/index.php?page=rules
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #6 (permalink)  
Old Oct 30th, 2007, 05:52
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

it basically center the #image div, not the image inside it..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #7 (permalink)  
Old Oct 30th, 2007, 06:04
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

Quote:
Originally Posted by monie View Post
it basically center the #image div, not the image inside it..
what? if that's the case why wouldll the image even center?
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #8 (permalink)  
Old Oct 30th, 2007, 06:08
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

In that case, set the #image div width and height to the size of your image. If you don't specify them, the #image div will expand into it's parent div size.. that would be your #content3 div.. there you go..

HTML: Select all
#image {
    margin: 0 auto;
    width: 182px;
    height: 182px;
}
you might want to try giving your div a border so that you could see where they are in your page, just for testing tho..
Now you know what is the magic word huh?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Oct 30th, 2007 at 06:14.
Reply With Quote
  #9 (permalink)  
Old Oct 30th, 2007, 07:22
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

This comes up again and again.

<img>s are inline elements. To centre something, it must be formatted as a block-level element.

You can either put a <div> (these are block-level) around it as monie suggested, and centre the <div>; or you can use the CSS:

Code: Select all
#image {
display: block;
margin: 0 auto;
}
You do not need to specify a width/height in the CSS. These are in the HTML.

I looked at your CSS, and I could not find any style rules relating to #image. I did find a lot of absolute positioning, however, which will cause you problems because, frankly, you don't have the skill to use it. The Lord moves in mysterious ways!
Reply With Quote
  #10 (permalink)  
Old Oct 30th, 2007, 07:37
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

What a funny reply there Mike..

I did not know myself about the display: block; until you mention it! Thanks Mike, I learn something new today.

My solution will also work but not effective enough.
The real solution is what you have posted. Thanks..

Now we have another magic word for today: { display: block; }
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #11 (permalink)  
Old Oct 30th, 2007, 08:02
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

Quote:
Originally Posted by monie View Post
What a funny reply there Mike..

I did not know myself about the display: block; until you mention it! Thanks Mike, I learn something new today.

My solution will also work but not effective enough.
The real solution is what you have posted. Thanks..

Now we have another magic word for today: { display: block; }
Actually, there are occasions when your solution would be better. Specifically, when the <img> is a child of the <body>.

Since <img> is an inline element, and remains an inline element no matter how we change the formatting rules, you will get validation errors when the <img> is a direct child of the <body> -- because every inline element must have some block-level ancestor.

Of course, you can also fix all such errors forever by using a wrapper <div>, and most sites have several wrapper <div>s anyway.
Reply With Quote
  #12 (permalink)  
Old Oct 30th, 2007, 08:10
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

OIC... Thats another knowledge I get from you Thanks again..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #13 (permalink)  
Old Oct 30th, 2007, 17:12
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

LOL, you guys are too funny, lol... (I think that's why I like this site so much, lol.)
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #14 (permalink)  
Old Oct 30th, 2007, 17:14
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,661
Thanks: 0
Thanked 9 Times in 9 Posts
Re: Problems with centering in CSS.

Have you got this sorted yet?
Reply With Quote
  #15 (permalink)  
Old Oct 30th, 2007, 17:19
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

I'm not at home so I cannot do anythig yet. I am waiting for my mom to come get me. lol...
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #16 (permalink)  
Old Oct 30th, 2007, 17:20
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,661
Thanks: 0
Thanked 9 Times in 9 Posts
Re: Problems with centering in CSS.

Lol... Ok. If you encounter any problems, gimme a shout!!
Reply With Quote
  #17 (permalink)  
Old Oct 31st, 2007, 02:27
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

I have tried both way, and conformed it is working...
Now its up to you to test them..
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #18 (permalink)  
Old Oct 31st, 2007, 04:48
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

Okay,

So for the CSS if i put
HTML: Select all
#image {
 display: block;
 margin: 0 auto;
}
then for my HTML piece I would put
HTML: Select all
 <div id="image">
  <img src="http://www.newbreedjesusfreaks.com/images/rules/Jesus01.gif" alt="Rules Bottom logo"  width="180" height="179">
  </div>
Correct?
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
  #19 (permalink)  
Old Oct 31st, 2007, 05:02
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Problems with centering in CSS.

Wrong..!

HTML: Select all
#image .myimage{ /*Give your img a class and set it to display block here*/
display: block;
margin: 0 auto;
}

<div id="ThisIsYourParentDiv, you can set it to margin 0 auto to center them as well">
    <img class="myimage" src="http://www.newbreedjesusfreaks.com/images/rules/Jesus01.gif" alt="Rules Bottom logo" width="180" height="179">
</div>
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #20 (permalink)  
Old Oct 31st, 2007, 05:14
mcdanielnc89's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Missouri
Age: 19
Posts: 232
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problems with centering in CSS.

HTML: Select all
#centeredmage .image1 {
 display: block;
 margin: 0 auto;
}
HTML: Select all
<div id="centeredimage">
    <img class="image1" src="http://www.newbreedjesusfreaks.com/images/rules/Jesus01.gif" alt="Rules Bottom logo" width="180" height="179">
</div>
 

this?
Last Blog Entry: My blog? (Oct 18th, 2007)
Reply With Quote
Reply

Thread Tools

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
[SOLVED] Centering Vertically R8515198 Web Page Design 5 Dec 6th, 2007 11:05
[SOLVED] page centering issues VanderBOOM Web Page Design 12 Dec 4th, 2007 15:06
[SOLVED] Centering horizontally and vertically Emzi Web Page Design 4 Nov 1st, 2007 16:07
[SOLVED] Centering! mcdanielnc89 Web Page Design 20 Oct 21st, 2007 22:02
Tip : Vertical and Horizontal Centering - Solved! gwx03 Web Page Design 0 Dec 15th, 2003 06:11


All times are GMT. The time now is 13:29.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43