Follow

I have accidently centered an image with text-align: center and I have no idea why it works.

what the actual crap CSS

@redsPL It's because by default, img is a display: inline tag :3

@esheep they actually have it as a default? Holy crap, how comes that I didn't notice this until now?

Still, centering in CSS is hardcore.

@redsPL Yeah, it's not always intuitive. I guess you can notice it if you have an image and some text next to each other, as the text will wrap around the image.

@esheep The troubleshooting was even funnier as the image had no padding/margin and had a float:left. At first, it always stayed on the left, then after removing the float it was always centered. Fun stuff.

@redsPL Yeah, float removes the element from the normal page flow :3

@redsPL And text-align doesn't actually affect text, but display: inline elements

Sign in to participate in the conversation
niu.moe

Welcome to your niu world ! We are a cute and loving international community O(≧▽≦)O !