programming-examples/css/Centre an element of no specified width.html

42 lines
877 B
HTML
Raw Permalink Normal View History

2019-11-15 12:59:38 +01:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Centre an element of no specified width</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#wrapper{
position:relative;
width:60%;
background:pink;
position:relative;
border:2px solid blue;
height:250px;
}
#test{
position:absolute;
left:50%;
}
#testinner{
position:relative;
left:-50%;
background:#f9f;
border:2px solid #000;
}
</style>
</head>
<body>
<h1>Love Sayings</h1>
<div id="wrapper">
<div id="test">
<div id="testinner">
<p>Take away love, and our earth is a tomb.<br><br>
Robert Browning</p>
</div>
</div>
</div>
</body>
</html>