文字或图片元素在DIV中垂直居中
程序员文章站
2024-03-02 11:17:04
复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>untitled document</title>
<style type="text/css">
<!--
.frame{
float:left;
margin:2px;
}
.outer {
height: 250px;
width: 240px;
overflow: hidden;
background:gold;
position: static !important;
position: relative;
display: table !important;
}
#middle { /* for explorer only*/
position: absolute;
top: 50%;
}
#middle[id] {
display: table-cell;
vertical-align: middle;
position: static;
}
#inner { /* for explorer only */
position: relative;
top: -50%;
width: 100%;
margin: 0 auto;
text-align:center
}
</style>
</head>
<body>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner"><img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" /></div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">
<img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" /><br /><br />
<img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" />
</div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">图片与文本内容混合<br><img src="http://desk.blueidea.com/qtzy/gif/xsgs_21/xsgs_21004.gif" alt="" /><br>图片与文本内容混合</div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner"><span>图片与文本</span><img src="http://desk.blueidea.com/qtzy/gif/xsgs_21/xsgs_21004.gif" alt="" align="middle" /><span>图片与文本</span></div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br></div>
</div>
</div>
</div>
</body>
</html>
复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>untitled document</title>
<style type="text/css">
<!--
.frame{
float:left;
margin:2px;
}
.outer {
height: 250px;
width: 240px;
overflow: hidden;
background:gold;
position: static !important;
position: relative;
display: table !important;
}
#middle { /* for explorer only*/
position: absolute;
top: 50%;
}
#middle[id] {
display: table-cell;
vertical-align: middle;
position: static;
}
#inner { /* for explorer only */
position: relative;
top: -50%;
width: 100%;
margin: 0 auto;
text-align:center
}
</style>
</head>
<body>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner"><img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" /></div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">
<img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" /><br /><br />
<img src="http://bbs.blueidea.com/images/smilies/eek.gif" alt="" />
</div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">图片与文本内容混合<br><img src="http://desk.blueidea.com/qtzy/gif/xsgs_21/xsgs_21004.gif" alt="" /><br>图片与文本内容混合</div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner"><span>图片与文本</span><img src="http://desk.blueidea.com/qtzy/gif/xsgs_21/xsgs_21004.gif" alt="" align="middle" /><span>图片与文本</span></div>
</div>
</div>
</div>
<div class="frame">
<div class="outer">
<div id="middle">
<div id="inner">5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br>5454545445445<br></div>
</div>
</div>
</div>
</body>
</html>
推荐阅读
-
文字或图片元素在DIV中垂直居中
-
文字或图片元素在DIV中垂直居中
-
div中有一个marquee标签,marquee中有滚动显示的文字,如何让文字在div中垂直居中从右向左滚动显示?_html/css_WEB-ITnose
-
为啥在IE6中,A标签中的文字不能垂直居中呢?_html/css_WEB-ITnose
-
我这个li中的文字为什么在chrome下无法垂直居中?_html/css_WEB-ITnose
-
为啥在IE6中,A标签中的文字不能垂直居中呢?_html/css_WEB-ITnose
-
IE8 如何让无序列表中的文字与里面的div在垂直方向都居中_html/css_WEB-ITnose
-
我这个li中的文字为什么在chrome下无法垂直居中?_html/css_WEB-ITnose
-
div中有一个marquee标签,marquee中有滚动显示的文字,如何让文字在div中垂直居中从右向左滚动显示?_html/css_WEB-ITnose
-
div中图片和文字同一行实现垂直居中