0

I'm making a website with the little help of my dad who’s is working in <SNIP> . It is the professional site and which site I making it is just finished up an html, xhtml, and css tutorial for review and would like to know the html code for aligning an image in the center, left, or right area of the page using css.
not enclosing it in center tags.

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by MidiMagic
0

Unfortunately, the W3C deprecated center, and didn't give use anything that works reliably to replace it. They were thinking so much in terms of books and newspapers, that they didn't provide methods for centering things other than text.

How to align something depends on what that something is:

Text is aligned with the text-align style.

text-align: left;
text-align: center;
text-align: right;
text-align: justified;

You can float anything left, right, or none with the float style, but centering is not part of float.

float: left;

Most other things will center if you enclose them in a div set up as follows:

<style>
cend {margin-left: auto; margin-right: auto;
         border: none; padding: 0;
         text-align: center;}
ceni {clear: both;}
whf {width: 50%;}  // keep table from being full-width

<div class="cend">
  <table class="ceni whf">
    // table contents
  </table>
</div>

Images won't cent4er like everything else.

<style>
cenb {margin: 0; border: none; padding: 0;
         text-align: center;}
ceni {clear: both;}

<div class="cenb">
  <img src="myimage.jpg" class="ceni whf" />
</div>

They took away something simple and gave us a mess.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.