日期:2014-05-17 浏览次数:20863 次
<!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=gb_2312" /> <title>No Title</title> </head> <style> #container { width:800px; padding:0; margin:0 auto; height:100%;} #leftDiv { width:24%; float:left; text-align:center; line-height:600px; height:600px; display:block; background-color:#ccc; color:#f00;} #rightDiv { width:74%; float:right; text-align:center; line-height:600px; height:600px; display:block; background-color:#c00; color:#fff;} </style> <body> <div id="container"> <div id="leftDiv"> leftDiv </div> <div id="rightDiv"> rightDiv </div> </div> </body> </html>
------解决方案--------------------
float这里就不贴代码了,不用float的话,可以用定位来做,这种方法的优点是可以按DIV的顺序来决定优先显示的顺序,代码如下:
<!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" xml:lang="zh-CN" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> </head> <body> <style type="text/css"> body { font-size:9pt; text-align:center; } #container { position:relative; margin:auto; width:800px; height:200px; } #leftDiv { position:absolute; top:0; left:0; width:200px; height:200px; background:#ddd; } #rightDiv { position:absolute; top:0; right:0; width:600px; height:200px; background:#eee; } </style> 1、先显示leftDiv <div id="container"> <div id="leftDiv">leftDiv</div> <div id="rightDiv">rightDiv</div> </div> 2、先显示rightDiv <div id="container"> <div id="rightDiv">rightDiv</div> <div id="leftDiv">leftDiv</div> </div> </body> </html>
------解决方案--------------------