职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 1295|回复: 0

CSS高级教程之CSS的定位属性和实例

[复制链接]
yoyo 发表于 2007-8-15 11:05 | 显示全部楼层 |阅读模式
  CSS定位属性允许你对元素进行定位。

CSS 定位 (Positioning)实例:
定位:相对定位
本例演示如何相对于其正常位置来定位元素。
<html>
<head>
<style type=\"text/css\">
h2.pos_left
{
position:relative;
left:-20px
}
h2.pos_right
{
position:relative;
left:20px
}
</style>
</head>
<body>
<h2>This is a heading in normal position</h2>
<h2 class=\"pos_left\">This heading is moved left to its normal position</h2>

<h2 class=\"pos_right\">This heading is moved right to its normal position</h2>
<p>Relative positioning moves an element RELATIVE to its original position.</p>
<p>The style \"left:-20px\" subtracts 20 pixels from the element&#39;s original left position.</p>
<p>The style \"left:20px\" adds 20 pixels to the element&#39;s original left position.</p>
</body>
</html>定位:绝对定位
本例演示如何使用绝对值来定位元素。
<html>
<head>
<style type=\"text/css\">
h2.pos_abs
{
position:absolute;
left:100px;
top:150px
}
</style>
</head>
<body>
<h2 class=\"pos_abs\">This is a heading with an absolute position</h2>
<p>With absolute positioning, an element can be placed anywhere on a page. The heading below is placed 100px from the left of the page and 150px from the top of the page.</p>
</body>
</html>设置元素的形状
本例演示如何设置元素的形状。此元素被剪入这个形状中,然后被显示出来。
<html>
<head>
<style type=\"text/css\">
img
{
position:absolute;
clip:rect(0px 50px 200px 0px)
}
</style>
</head>
<body>
<p>The clip property is here cutting an image:</p>
<p><img border=\"0\" src=\"bookasp20.gif\" width=\"120\" height=\"151\"></p>
</body>
</html>溢出
本例演示当元素内容太大而超出规定区域时,如何设置溢出属性来规定相应的动作。
<html>
<head>
<style type=\"text/css\">
div
{
background-color:#00FFFF;
width:150px;
height:150px;
overflow: scroll
}
</style>
</head>
<body>
<p>The overflow property decides what to do if the content inside an element exceeds the given width and height properties.</p>
<div>
You can use the overflow property when you want to have better control of the layout. Try to change the overflow property to: visible, hidden, auto, or inherit and see what happens. The default value is visible.
</div>
</body>
</html>垂直排列图象
本例演示如何在文本中垂直排列图象。
<html>
<head>
<style type=\"text/css\">
img.top {vertical-align:text-top}
img.bottom {vertical-align:text-bottom}
</style>
</head>
<body>
<p>
This is an
<img class=\"top\" border=\"0\"
src=\"/i/example_moving.gif\" />
image inside a paragraph.
</p>
<p>
This is an
<img class=\"bottom\" border=\"0\"
src=\"/i/example_moving.gif\" />
image inside a paragraph.
</p>
</body>
</html>Z-index
Z-index可被用于将在一个元素放置于另一元素之后。
<html>
<head>
<style type=\"text/css\">
img.x
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<img class=\"x\" src=\"bulbon.gif\" width=\"100\" height=\"180\">
<p>Default z-index is 0. Z-index -1 has lower priority.</p>
</body>
</html> Z-index
上面的例
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-6 00:01 , Processed in 0.122136 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表