css效果 position属性

1.让内部元素跑到包含元素外面,只有改变内部元素的定位环境.
[1]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Positioning demo</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<style type="text/css">
* {margin:0px; padding:0;}   
body {background-color:#FFC;}
/* div#outer_div {width:250px; margin:100px 40px; border-top:3px solid red;} zhao*/
div#outer_div {width:250px; margin:100px 40px; border:5px solid red;} 
div#inner_div {top:10px; left:20px; background:#AAA;}
</style>
</head>
<body>
<div id="outer_div">
  <div id="inner_div"> This some text for a paragraph to demonstrate contextual
    positioning. Here are two divs, one nested in the other. The outer div has
    red top border and the inner one has a gray background. Both elements have default static positioning.</div>
</div>
</body>
</html>



[2]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Positioning demo</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<style type="text/css">
* {margin:0px; padding:0;}   
body {background-color:#FFC;}
/* div#outer_div {width:250px; margin:100px 40px; border-top:3px solid red;} zhao*/
div#outer_div {width:250px; margin:100px 40px; border:5px solid red;} 
div#inner_div {position:absolute; top:10px; left:20px; background:#AAA;}
</style>
</head>
<body>
<div id="outer_div">
  <div id="inner_div"> This some text for a paragraph to demonstrate contextual
    positioning. Here are two divs, one nested in the other. The outer div has
    red top border and the inner one has a gray background. The inner div now
    has absolute positioning, so it positions itself relative to the default
    positioning context, body.</div>
</div>
</body>
</html>



[3]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Positioning demo</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<style type="text/css">
* {margin:0px; padding:0;}   
body {background-color:#FFC;}
/* div#outer_div {position:relative; width:250px; margin:100px 40px; border-top:3px solid red;} zhao */
div#outer_div {position:relative; width:250px; margin:100px 40px; border:5px solid red;}
div#inner_div {position:absolute; top:10px; left:20px; background:#AAA;}
</style>
</head>
<body>
<div id="outer_div">
  <div id="inner_div"> This some text for a paragraph to demonstrate contextual
    positioning. Here are two divs, one nested in the other. The outer div has
    red top border and the inner one has a gray background. The inner div has
    absolute positioning, and the outer div, with relative positioning, now
    becomes its positioning context&mdash;the inner div now positions itself relative to the outer div. </div>
</div>
</body>
</html>



[4]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Positioning demo</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<style type="text/css">
* {margin:0px; padding:0;}   
body {background-color:#FFC;}
/* div#outer_div {position:relative; width:250px; margin:100px 40px; border-top:3px solid red;} zhao */
div#outer_div {position:absolute; width:250px; margin:100px 40px; border:5px solid red; top:50px; left:50px; }
div#inner_div {position:absolute; top:10px; left:20px; background:#AAA;}
</style>
</head>
<body>
<div id="outer_div">
  <div id="inner_div"> This some text for a paragraph to demonstrate contextual
    positioning. Here are two divs, one nested in the other. The outer div has
    red top border and the inner one has a gray background. The inner div has
    absolute positioning, and the outer div, with relative positioning, now
    becomes its positioning context&mdash;the inner div now positions itself relative to the outer div. </div>
</div>
</body>
</html>



你可能感兴趣的:(html,XHTML,css)