[SOLVED] Centering!

This is a discussion on "[SOLVED] Centering!" within the Web Page Design section. This forum, and the thread "[SOLVED] Centering! are both part of the Design Your Website category.


 Subscribe in a reader

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

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 21st, 2007, 03:05
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] Centering!

ok. my css is this...
HTML: Select all
img.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

my html is this...
HTML: Select all
<IMG class="displayed" src="http://www.webforumz.com/images/aboutus.png" alt="About us">

it doesn't center. lol
Last Blog Entry: My blog? (Oct 18th, 2007)

Last edited by mcdanielnc89; Oct 21st, 2007 at 18:27. Reason: WHen inserting code i didn't put the < in the front, but still doesn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 21st, 2007, 04:40
Junior Member
Join Date: Nov 2006
Location: Los Angeles
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Dare I point out the obvious, though I'm sure its just a mistake:
Code: Select all
<img class="displayed" src="http://www.webforumz.com/images/aboutus.png" alt="About Us" />
You need to open the image tag. I've found that centering objects like images is done best like this:
Code: Select all
<div align="center">
     <img src="http://www.webforumz.com/images/aboutus.png" alt="About Us" />
</div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 21st, 2007, 08:56
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Quote:
Originally Posted by trandrus View Post
I've found that centering objects like images is done best like this:
Code: Select all
<div align="center">
     <img src="http://www.webforumz.com/images/aboutus.png" alt="About Us" />
</div>
That method is deprecated. Use CSS and auto margins instead.

Applying margin: 0 auto; to an element will cause it to be centred inside the parent container (but this fails on IE5 and IE6 in quirks mode).

Do a search, either here or on Google. This has been covered many, many times.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 21st, 2007, 16:50
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Centering!

This should work as it usually requires you to specify a height and width:
HTML: Select all
img.displayed {
display: block;
margin: 0 auto;
height: 100px; 
width: 100px;
}
Obviously change the height and width.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 21st, 2007, 17:51
Junior Member
Join Date: Nov 2006
Location: Los Angeles
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Total server work required for CSS solution: 571B
Total server work required for align='center': 528B

Try it yourself:
http://www.rossandrus.net/examples/d...d/standard.php
http://www.rossandrus.net/examples/d...deprecated.php

Test the load time:
http://www.websiteoptimization.com/services/analyze/

That's not even taking IE5 and 6 into consideration. The CSS solution also forces you to display the image as block which is less flexible for things like rows of horizontally centered icons, etc. Deprecated doesn't always mean bad.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 21st, 2007, 18:03
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: Centering!

hmm ok so which way is teh way to do itr if it's depreciated, and tyhe height and width would be pointless to do as that vlass is used for several other images...
Last Blog Entry: My blog? (Oct 18th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 21st, 2007, 18:08
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Centering!

I just told you how to do iit the non-depcricated way.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 21st, 2007, 18:11
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Quote:
Originally Posted by trandrus View Post
Total server work required for CSS solution: 571B
Total server work required for align='center': 528B

Try it yourself:
http://www.rossandrus.net/examples/d...d/standard.php
http://www.rossandrus.net/examples/d...deprecated.php

Test the load time:
http://www.websiteoptimization.com/services/analyze/

You've got to be kidding me. You're talking about a mere 8% increase in server work, for a tiny total amount of work, on a presentational effect that will be used sparingly.

Compared to the total work required for a typical webpage, this is irrelevant. It's far more important to understand the reasons for preferring CSS-based presentation to HTML-based presentation. Saving a few bytes here and there is of dubious value.

Moreover, since both pages are invalid HTML, they hardly constitute good examples. Finally, note that although the CSS solution has an initial performance cost, it becomes more efficient the more you use it.

Quote:
The CSS solution also forces you to display the image as block which is less flexible for things like rows of horizontally centered icons, etc.
No it doesn't. You can make the image inline, and place a <div> around it instead. Then centre the <div>.

Quote:
Deprecated doesn't always mean bad.
Yes it does, actually. http://en.wikipedia.org/wiki/Deprecated

Last edited by MikeHopley; Oct 21st, 2007 at 18:15.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 21st, 2007, 18:20
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: Centering!

Quote:
Originally Posted by alexgeek View Post
This should work as it usually requires you to specify a height and width:
HTML: Select all
img.displayed {
display: block;
margin: 0 auto;
height: 100px; 
width: 100px;
}
Obviously change the height and width.
Okay, I guess I'm not quite understanding this aparently. WHy do I need to state the height and width if the css class is used for more than one image? If i do that; then wouldn't all images be the same and disportioned if they're not the same size?
Last Blog Entry: My blog? (Oct 18th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Oct 21st, 2007, 18:24
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

You should not state the height and width. For images inserted via the <img> element (as opposed to CSS backgrounds), the height and width are given in the HTML.

Width is required for centring other boxes (<div>s, typically) that lack an inherent width.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 21st, 2007, 18:28
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: Centering!

If that is the case MikeHopley then what is wrong with my code to make it not center? Is my CSS wrong?(Obviously it has to be)
Last Blog Entry: My blog? (Oct 18th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Oct 21st, 2007, 18:46
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Quote:
Originally Posted by mcdanielnc89 View Post
If that is the case MikeHopley then what is wrong with my code to make it not center? Is my CSS wrong?(Obviously it has to be)
What browser are you using? Can you provide a link?

I suspect this is IE nuttiness. But the simplest explanation requires that I know more about your browser/code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Oct 21st, 2007, 18:47
Junior Member
Join Date: Nov 2006
Location: Los Angeles
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Quote:
You're talking about a mere 8% increase in server work, for a tiny total amount of work, on a presentational effect that will be used sparingly
...
Finally, note that although the CSS solution has an initial performance cost, it becomes more efficient the more you use it.
If it's going to be used sparingly, then why does CSS make sense?
Quote:
It's far more important to understand the reasons for preferring CSS-based presentation to HTML-based presentation.
Yes, I agree it is important to understand the difference between the two. However, I would argue that it's far more important to understand the advantages and disadvantages for both cases. If you're trying to center a horizontal navigation bar on the page, why would you go through all the trouble of setting it up in CSS? The real power of CSS comes from targeting child objects that are repeatedly used in a page which decreases the needed amount of markup.
Quote:
Moreover, since both pages are invalid HTML, they hardly constitute good examples.
They're invalid because there is no doctype because I wrote it by hand in about 2 minutes. Google makes this same mistake, by the way:
http://validator.w3.org/check?uri=www.google.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Oct 21st, 2007, 18: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: Centering!

Yes it is IE7, and a link to where one of the images not responding is located here.
Last Blog Entry: My blog? (Oct 18th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Oct 21st, 2007, 19:08
Junior Member
Join Date: Nov 2006
Location: Los Angeles
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

You need to set the class of your images to link with the information in your stylesheet. Your code modified:
Code: Select all
<div>
      <img class="mycenter" src="images/monthlysignin.png" alt="Monthly Sign-In Logo">
      <br>
      <br>
      <p class="style7">
        NBJF's Sign-in will be discontinued until the site is up
        and running 100%!<br>
        Thank you for your cooperation!
      </p>
      <br>
      <img class="mycenter" src="http://www.newbreedjesusfreaks.com/images/saesons.jpg"  alt="Seasons Logo" />
    </div>
And add the class to your stylesheet:
Code: Select all
img.mycenter {
    display:block;
    margin:0 auto;
}
If this doesn't work then it might be a browser bug related issue, in which case you should consult:
http://centricle.com/ref/css/filters/
But make sure your code is sound before you start looking into browser discrepancies.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Oct 21st, 2007, 19:09
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Centering!

Quote:
Yes it is IE7, and a link to where one of the images not responding is located here.
You need to specify width and height in the html. Like this:

Code: Select all
<img src="http://www.newbreedjesusfreaks.com/images/saesons.jpg" alt="Seasons Logo" width="200" height="100">
Quote:
Originally Posted by trandrus View Post
If you're trying to center a horizontal navigation bar on the page, why would you go through all the trouble of setting it up in CSS?
Because:
  1. It's no trouble if you actually know what you're doing.
  2. The CSS way is much more flexible, allowing you to change your mind about the style of the navbar.
Quote:
The real power of CSS comes from targeting child objects that are repeatedly used in a page which decreases the needed amount of markup.
The real power of CSS is the systematic separation of style from content, allowing site-wide changes to be made with minimal effort, and reducing the overall complexity of your code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Oct 21st, 2007, 19:24
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: Centering!

ok. my css is

Code: Select all
img.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto;
}
html is now...

Code: Select all
<img src=
  "http://www.newbreedjesusfreaks.com/images/saesons.jpg"
  alt="Seasons Logo" width="382" height="271" class="displayed">
Last Blog Entry: My blog? (Oct 18th, 2007)