用css给不定高的<div class=“tips”><div>垂直居中,请写出三种方法。

html-css07

用css给不定高的<div class=“tips”><div>垂直居中,请写出三种方法。,第1张

1.定位top50% margin-top:-50% 2.给父级设置高和行高相等,3.用一个“ghost”伪元素(看不见的伪元素)和 inline-block / vertical-align 可以搞定居中,非常巧妙。但是这个方法要求待居中的元素是 inline-block,不是一个真正通用的方案。

你给第二个#top_tel加个float:left然后top的总宽度要大于430+261+368+132+20,不设宽度也行跟高度没关系 margin:0px 0px 0px 0px 可以缩写为margin:0px一样的话没必要去每个都写,还有,你既然#top_tel{width:261pxheight:69pxmargin:15px 0px 0px 430pxbackground:url(images/TEL.jpg) no-repeat}

要左边距430px为什么不把这个做成这样的,这两个都右漂浮不是更好

<div id="top_tips">565656</div>

<div id="top_tel"></div>

小小的给你改下

#top{ background:url(images/topbj.gif) repeat-x #000000height:92px}

#top_logo{width:368pxheight:52pxfloat:leftpadding:20px 0px 0px 20px}

#top_tel{width:261pxheight:69pxmargin-top:15pxbackground:url(images/TEL.jpg) no-repeatfloat:right}

#top_tips{background:url(images/tips.gif) no-repeat top leftwidth:132pxheight:18pxfloat:rightmargin:0px}

网页代码:

<div id="top">

<div id="top_logo"><a href="#"><img src="images/logo.jpg" border="0" alt="网站LOGO" /></a></div>

<div id="top_tips">565656</div>

<div id="top_tel"></div>

</div><!--头部结束-->