Vertical-align not working with XHTML 1.0 Transitional doctype?

流过昼夜 提交于 2020-01-21 09:11:48

问题


Okay, so I messed around for a long time trying to center an image vertically within a div using vertical-align:middle (while also centering it horizontally with text-align:center) and I was wracking my brains trying to figure out why in the world it wasn't working.

.container{
    height:200px;
    width:200px;
    text-align:center;
    line-height:200px;
    }

    .image{
    vertical-align:middle;
    }

It looked to me like it should, but it didn't, turns out that the thing that solved it was changing the doctype from

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

to

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

When I do that, the image is centered.

How come? I was under impression that the strict doctype allows less attributes than the transitional one, is that wrong? I can't seem to find any information regarding vertical-align and XHTML 1.0 Transitional, when it comes to Strict however I find all kinds of information about it not allowing this and that, so I'm a bit confused. I'd rather not use Strict for this particular site, but I do need to use vertical-align.

Can anybody shed some light on this please? Thanks


回答1:


The doctype does not affect what CSS does. However, the second doctype you tried does trigger quirks mode which you don't want to be in because it uses the wrong box model. New web pages should not be using transitional doctypes either. Always use strict or the newer doctype: <!doctype html>



来源:https://stackoverflow.com/questions/5506910/vertical-align-not-working-with-xhtml-1-0-transitional-doctype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!