HTML/CSS/Box Model/bottom
Содержание
- 1 Absolute offset
- 2 Absolute Outside Top Right with 100% bottom
- 3 Absolute to left and bottom
- 4 bottom aligns the bottom side of an absolute element to the bottom side of its container
- 5 Bottom always
- 6 Bottom auto
- 7 Bottom-left Absolute positioned element
- 8 Bottom-right Absolute positioned element
- 9 horizontally stretching content with top, right and left
- 10 positioning and sizing
- 11 Position layer
- 12 Use bottom to offset the bottom of an element from the bottom.
Absolute offset
<!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" xml:lang="en">
<head>
<title>Opposing Offset Properties</title>
<style rel="stylesheet" type="text/css">
div#offset-four {
background: yellow;
border: 1px solid rgb(128, 128, 128);
position: absolute;
top: 20px;
right: 20px;
bottom: 20px;
left: 20px;
}
</style>
</head>
<body>
<div id="offset-four">
</div>
</body>
</html>
Absolute Outside Top Right with 100% bottom
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css" title="text/css">
* .parent {
left: 300px;
top: 300px;
position: relative;
height: 140px;
width: 200px;
background: black;
}
* .right {
position: absolute;
left: 100%;
margin-left: 5px;
background: red;
}
* .top {
position: absolute;
bottom: 100%;
margin-bottom: 5px;
background: red;
}
</style>
</head>
<body>
<div class="parent">Parent
<p class="top right">Absolute Outside Top Right</p>
</div>
</body>
</html>
Absolute to left and bottom
<!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" xml:lang="en">
<head>
<title></title>
<style rel="stylesheet" type="text/css">
body {
background: pink;
font: 12px sans-serif;
margin: 0;
padding: 0;
}
p {
background: red;
border: 1px solid green;
padding: 5px;
margin: 5px;
}
p#absolute {
position: absolute;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu
massa.
</p>
<p id="absolute">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu
massa.
</p>
</body>
</html>
bottom aligns the bottom side of an absolute element to the bottom side of its container
<!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">
<head>
<title></title>
<style type="text/css">
* .container {
position: relative;
background: black;
}
* .box {
position: absolute;
overflow: auto;
visibility: visible;
z-index: 1;
bottom: 20px;
width: 220px;
height: 100px;
margin: 10px;
padding: 10px;
background: red;
}
* .before {
z-index: 2;
width: 100px;
height: 400px;
left: 400px;
right: auto;
top: 100px;
bottom: auto;
background: yellow;
}
</style>
</head>
<body>
<div class="container">
<div>BEFORE</div>
<div class="before">ABSOLUTE BEFORE</div>
<div class="box">this is a test. this is a test. </div>
</div>
</body>
</html>
Bottom always
<!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" xml:lang="en">
<head>
<title></title>
<style rel="stylesheet" type="text/css">
body {
background: lightyellow;
font: 12px sans-serif;
margin: 0;
padding: 0;
}
p {
background: red;
border: 1px solid black;
padding: 5px;
margin: 5px;
}
p#absolute {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</p>
<p id="absolute">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</p>
</body>
</html>
Bottom auto
<!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">
<head>
<title></title>
<style type="text/css">
#abs {
width: auto;
height: auto;
left: auto;
bottom: auto;
position: absolute;
background: blue;
}
</style>
</head>
<body>
<span id="abs">Shrinkwrapped Absolute</span>
</body>
</html>
Bottom-left Absolute positioned element
<!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" xml:lang="en">
<head>
<title>Absolute Positioning</title>
<style rel="stylesheet" type="text/css">
body {
background: yellowgreen;
}
div {
position: absolute;
background: yellow;
padding: 5px;
width: 100px;
height: 100px;
}
div#bottom-left {
bottom: 0;
left: 0;
border-right: 1px solid black;
border-top: 1px solid black;
background: blue;
}
</style>
</head>
<body>
<div id="bottom-left">
Bottom, Left
</div>
</body>
</html>
Bottom-right Absolute positioned element
<!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" xml:lang="en">
<head>
<title>Absolute Positioning</title>
<style rel="stylesheet" type="text/css">
body {
background: yellowgreen;
}
div {
position: absolute;
background: yellow;
padding: 5px;
width: 100px;
height: 100px;
}
div#bottom-right {
bottom: 0;
right: 0;
border-left: 1px solid black;
border-top: 1px solid black;
background: red;
}
</style>
</head>
<body>
<div id="bottom-right">
Bottom, Right
</div>
</body>
</html>
horizontally stretching content with top, right and left
<!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" xml:lang="en">
<head>
<title></title>
<style rel="stylesheet" type="text/css">
body {
background: lightyellow;
font: 12px sans-serif;
margin: 0;
padding: 0;
}
p {
background: red;
border: 1px solid black;
padding: 5px;
margin: 5px;
}
p#absolute {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</p>
<p id="absolute">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</p>
</body>
</html>
positioning and sizing
<!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" xml:lang="en">
<head>
<title></title>
<style rel="stylesheet" type="text/css">
body {
background: pink;
font: 12px sans-serif;
margin: 0;
padding: 0;
}
p {
background: red;
border: 1px solid green;
padding: 5px;
margin: 5px;
}
p#absolute {
position: absolute;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu
massa.
</p>
<p id="absolute">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec eu
massa.
</p>
</body>
</html>
Position layer
<html>
<head>
<style type="text/css">
div.layer1 {
position:absolute;
left:75px;
top:75px;
color:red
}
div.layer2 {
position:absolute;
right:75px;
bottom:75px;
font-family: arial;
color:blue;
font-weight:bold
}
</style>
</head>
<body>
<div class="layer1">
<h1>Positioning Layers</h1>
<p>This is the first layer1 paragraph</p>
<p>This is the second layer1 paragraph</p>
</div>
<div class="layer2">
<p>This is the first layer2 paragraph</p>
<p>This is the second layer2 paragraph</p>
</div>
</body>
</html>
Use bottom to offset the bottom of an element from the bottom.
<!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">
<head>
<title></title>
<style type="text/css">
div,p,em {
margin: 10px;
padding: 10px;
background-color: white;
border-left: 1px solid gray;
border-right: 2px solid black;
border-top: 1px solid gray;
border-bottom: 2px solid black;
}
* .pos {
position: relative;
bottom: -10px;
}
</style>
</head>
<body>
<div class="relative">
<p class="pos">Positioned</p>
</div>
</body>
</html>