问答详情
源自:2-1 vertical-align起作用的前提

不定文字和图片垂直居中不起作用,求教师和同学指出错误


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

<title></title>

<style type="text/css">

*{

margin: 0;

padding: 0;

}

html,body,.list{

width: 100%;

height: 100%;

}

.list{

overflow: auto;

}

.test-list{

border: 1px solid;

}

.test-list>span{

display: inline-block;

width: 210px;

vertical-align: middle;

}

.test-list>img{

vertical-align: middle;

}

</style>

</head>

<body>

<div class="list">

<div class="test-list">

<span>文字</span>

<img src="img/mm1.png" width="80px"/>

</div>

<div class="test-list">

<span>文字</span>

<span>文字</span>

<img src="img/mm1.png" width="80px"/>

</div>

<div class="test-list">

<span>文字</span>

<span>文字</span>

<span>文字</span>

<img src="img/mm1.png" width="80px"/>

</div>

<div class="test-list">

<span>文字</span>

<span>文字</span>

<span>文字</span>

<span>文字</span>

<img src="img/mm1.png" width="80px"/>

</div>

<div class="test-list">

<span>文字</span>

<span>文字</span>

<span>文字</span>

<span>文字</span>

<span>文字</span>

<img src="img/mm1.png" width="80px"/>

</div>

</div>

</body>

</html>



提问者:慕盖茨5287063 2019-06-17 00:33

个回答

  • 慕容1529948
    2019-08-12 14:34:09

    指定负长度值和百分比值会使元素降低

  • 慕盖茨5287063
    2019-06-17 00:35:26

    效果如下,我都是按照老师教的写的,不知道那里出了问题

    https://img3.mukewang.com/5d066fc900017e4e04150764.jpg