div元素(css)定位

1.定位:相对定位(position:relative)

<html>
<head>
<style type="text/css">
h2.pos_left
{
position:relative;
left:-20px
}
h2.pos_right
{
position:relative;
left:20px
}
</style>
</head>

<body>
<h2>我是标题</h2>
<h2 class="pos_left">我是标题向左移动</h2>
<h2 class="pos_right">我是标题向右移动</h2>
</body>

效果就是:
--------------------------------我是标题--------------------------------
-----------------------------我是标题向左移动------------------------
----------------------------------我是标题向右移动-------------------
2.绝对定位(position:absolute)

<html>
<head>
<style type="text/css">
h2.pos_abs
{
position:absolute;
left:100px;
top:150px
}
</style>
</head>

<body>
<h2 class="pos_abs">我是绝对定位的标题</h2>
</body>

</html>

效果:
·---------------------------------------------
·
·
· ·············我是绝对定位的标题
·
·


3.固定定位(position:fixed;)

<html>
<head>
<style type="text/css">
p.one
{
position:fixed;
left:5px;
top:5px;
}
p.two
{
position:fixed;
top:30px;
right:5px;
}
</style>
</head>
<body>

<p class="one">我是1在这。</p>
<p class="two">我是2在这。</p>

</body>
</html>

效果:

·······我是1在这。
···········································································································我是2在这。

其他的根据padding和margin去控制、精确位置。

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值