You are here:

HTML/Question about aligning

Advertisement


Question
Hello,

Can you tell me why text-align:center not only centers text, but images as well? I'm trying to get images on my webpage to stay to the left, but with the text centered under each image.

Answer
Text-align center should only center text, but like any CSS, it depends how your code is structured.  Try a structure like this:

<img src="myimage.jpg" alt="" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sit amet augue ut ipsum mattis commodo eget at erat. Morbi viverra erat vel fermentum tristique. Vestibulum non dictum erat, sit amet pretium ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur tortor dolor, lobortis et velit in, euismod consequat metus. Fusce lacus est, tempor vitae leo a, mollis condimentum elit. Duis sed vehicula elit. Etiam imperdiet condimentum eleifend.</p>

And change it to be marked up like this:

<img src="myimage.jpg" alt="" style="float:left" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sit amet augue ut ipsum mattis commodo eget at erat. Morbi viverra erat vel fermentum tristique. Vestibulum non dictum erat, sit amet pretium ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur tortor dolor, lobortis et velit in, euismod consequat metus. Fusce lacus est, tempor vitae leo a, mollis condimentum elit. Duis sed vehicula elit. Etiam imperdiet condimentum eleifend.</p>


That should do!

HTML

All Answers


Answers by Expert:


Ask Experts

Volunteer


Dan Stephenson

Expertise

I am a professional Web Designer & Developer. I work with HTML, XHTML and CSS every day, and would be glad to help with your problems, and answer your questions.

Experience


Experience in the area I have been a web designer/developer since 1997. I started developing websites with HTML 3.2 and using tables for layout. In 2006 I received my degree in Computational Media, and now work full time as a Webmaster and Interactive Media Author, as well as teaching continuing education courses on HTML, CSS and ActionScripting at my local college. Currently I design with XHTML and CSS - no tables and much cleaner and more accessible code and allows the designer more freedom and flexibility than tables.

Education/Credentials
New Media Production & Design Degree - SAIT Polytechnic

©2016 About.com. All rights reserved.