日期:2014-05-17  浏览次数:20721 次

CSS控制文字与图片垂直居中的问题? 有测试样例
<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "UTF-8 "%>
<%
String   path   =   request.getContextPath();
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
    <head>
        <base   href= " <%=basePath%> ">
       
        <title> My   JSP   'css.jsp '   starting   page </title>
       
<meta   http-equiv= "pragma "   content= "no-cache ">
<meta   http-equiv= "cache-control "   content= "no-cache ">
<meta   http-equiv= "expires "   content= "0 ">        
<meta   http-equiv= "keywords "   content= "keyword1,keyword2,keyword3 ">
<meta   http-equiv= "description "   content= "This   is   my   page ">
<!--
<link   rel= "stylesheet "   type= "text/css "   href= "styles.css ">
-->
<style   type= "text/css ">
#d{background:orange;}
</style>
    </head>
   
    <body>
    <div   id= "d ">
<p   class= "pHeight "> 我想把这行字与右边的图片垂直对齐 <img   src= "http://www.csdn.net/images/logo_csdn.gif "   alt= " "   /> </p>
  </div>
    </body>
</html>

==========================================

把图片和文字垂直对齐的问题,有什么简单的办法?类似line-height的控制方式。。如果设定每个元素的margin-top也可以,就是觉得烦琐,想找个统一控制的方法。。。

有谁有研究么???

------解决方案--------------------
用表格最快了...想那多干什么呢.
------解决方案--------------------
很简单,试一下 <img style= "vertical-align:middle; "> ,当然写成img.vmiddle{vertical-align:middle;}放在 <style> .... </style> 里调用也是可以的。
------解决方案--------------------
<img align= "absmiddle "
------解决方案--------------------
将图片绝对居中,语法就是楼上写的align= "absmiddle "