<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>不确定高度的内容能相对左邻右舍和父元素垂直居中提供一个思路</title>
<style type="text/css">
.section{
width: 100%;
overflow: hidden;
font-size: 0; /*这里为0是因为子元素inline-block 之间可能有空格*/
background-color: #eee;
}
.picture{
width: 33.333%;
vertical-align: middle;
display: inline-block; /*float 就是block布局 vertical-align不起作用*/
}
.picture img{
width: 100%;
}
.text{
width: 33.333%;
vertical-align: middle; /*两个都要加*/
display: inline-block;
padding: 0 20px;
box-sizing: border-box;
background-color: #ccc;
}
.text h2{
font-size: 20px;
line-height: 48px;
margin: 0;
}
.text p{
font-size: 14px;
line-height: 22px;
margin: 0; /*谷歌的-webkit-margin-after 和 -webkit-margin-before很友(tao)好(yan)呀*/
}
</style>
</head>
<body>
<div class="section">
<div class="picture"><img src="http://sucai.epweike.com/uploadfile/2014/0210/thumb_500_332_20140126114608129.jpg" alt="" /></div>
<div class="text">
<h2>DIV CLASS=TEXT</h2>
<p>这里是一个<strong>字数长度不确定</strong>的段落,到底有多少个字我也不知道,有几行我也不清楚,高度是随意的,但是我依然希望他能相对于图片垂直剧中,随时修改文字都可以。但是高度还是不要大于左右两个图片的高度吧,否则也没意义呀。ps:图片来源于网络</p>
</div>
<!--左右都有-->
<div class="picture"><img src="http://sucai.epweike.com/uploadfile/2014/0210/thumb_500_332_20140126114608129.jpg" alt="" /></div>
</div>
</body>
</html>
不确定高度的内容能相对左邻右舍和父元素垂直居中提供一个思路
最新推荐文章于 2021-01-17 14:39:59 发布