CSS相對定位的例子

來源:互聯網
上載者:User

讓第二個div脫離文檔流,向右下方移動,原來的空間會保留。

html檔案:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>CSS相對定位的例子</title>
<link rel="stylesheet" style="text/css" href="test1.css" />
</head>
<body>
<div class="div1">
內容1
</div>
<div class="div1" id="special">
內容2
</div>
<div class="div1">
內容3
</div>
<div class="div1">
內容4
</div>
</body>
</html>

CSS檔案內容:

.div1{
width:70px;
height:30px;
margin-left:5px;
background:silver;
float:left; /*左浮動*/
}
#special{
position:relative;/*相對定位*/
left:40px;
top:100px;
}

效果如下圖:

本文地址:http://www.bianceng.cn/web/Css/201608/50317.htm

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.