Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If the user wants to center an image in the editor the image gets the class aligncenter. Now I looked up the CSS for this class and put it in my theme. But there is a link on the image (default) and the image is only a thumbnail. So I can click the whole area but the image only takes up a piece of this area. I don't want this behavior. What can I do?

This is my CSS for the class aligncenter:

.aligncenter {
    clear: both;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

This is the HTML-Code:

<a href="http://www.domain.com/wp-content/uploads/2012/04/F2_20_gr.jpg" class="fancybox" rel="fancybox" title="System">
    <img width="150" height="150" alt="" src="http://www.domain.com/wp-content/uploads/2012/04/F2_20_gr-150x150.jpg" title="System" class="size-thumbnail wp-image-91 aligncenter">
</a>
share|improve this question
1  
Voting to close, this is not a WordPress questions, please read the wordpress.stackexchange.com/faq – Wyck Apr 30 '12 at 14:14
Didn't know where to put this. But I think theme development would match the criteria. – testing Apr 30 '12 at 14:22
@Wyck: Isn't it a theme development question? The Editor built in in Wordpress adds the class aligncenter. What is the common way to handle this class? I think there is more to do than defining the CSS and therefore a programming question. – testing Apr 30 '12 at 16:27

closed as off topic by Wyck, EAMann Apr 30 '12 at 16:11

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

If the image size will stay the same, move the aligncenter class to the <a> tag and set the width and height properties to the size of the image.

P.S. I think this is off topic because it deals with CSS and not just WordPress.

share|improve this answer
Hmmm. I'm using the default settings for posting a picture on a page. How should I add the aligncenter to the anchor, when Wordpress puts it automatically to the image? How do I read out the width and height of the image? The only way I know is doing it with PHP but how should I manage this? It comes from the editor itself ... – testing Apr 30 '12 at 14:21
Sorry, I should have figured the image size was going to be dynamic, so disregard that part. Just cut and paste the aligncenter class to the anchor tag. – Joseph Apr 30 '12 at 16:45
Thanks for your supprt! Now the question is: How do I set a class to the anchor? The anchor don't get a class name by default (because of the editor in Wordpress). – testing Apr 30 '12 at 17:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.