時間:2023-09-08 01:06:01 | 來源:網(wǎng)站運營
時間:2023-09-08 01:06:01 來源:網(wǎng)站運營
CSS利用浮動與定位進行網(wǎng)頁布局:<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代碼如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7499')">web學(xué)習(xí)群:751196913</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7499><div id="main"> <div id="box1">box1</div> <div id="box2">box2</div> <div class="clear"></div></div>#main{ width:100%; }#box1{ float:left; width:40%;}#box2{ float:right; width:60%;}.clear{ clear:both;}</td> </tr> </table>
這是一個一行兩列的例子,其中clear的作用是不讓浮動元素下面的元素環(huán)繞在它周圍。<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE">
代碼如下:</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7804')">web學(xué)習(xí)群:751196913</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7804><div id="main"> <div id="box1">box1</div> <div id="box2">box2</div></div> #main{ position:relative;width:100%;}#box1{ position:absolute; top:0; left:0; width:40%;}#box2{position:absolute; top:0; right:0; width:60%;}</td> </tr> </table>
通常,做彈出菜單的時候,我會用到定位,父元素相對定位position:relative,其中的子元素絕對定位position:absolute,通過top,right,bottom,left的值來控制子元素的位置,要注意的是子元素的位置將相對于父元素,而不是整個頁面。關(guān)鍵詞:布局,定位,利用,浮動
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。